Submission #7117767


Source Code Expand

Copy
<?php
define('MOD', 10 ** 9 + 7);

fscanf(STDIN, '%d %d', $n, $k);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));

$cnt1 = $cnt2 = 0;
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $n; $j++) {
        if ($i === $j) continue;

        if ($i < $j && $a[$i] > $a[$j]) $cnt1++;
        elseif ($i > $j && $a[$i] > $a[$j]) $cnt2++;
    }
}

$x1 = (1 + $k) * $k / 2 % MOD;
$x2 = (1 + $k - 1) * ($k - 1) / 2 % MOD;
$ans = (($cnt1 * $x1) % MOD + ($cnt2 * $x2) % MOD) % MOD;
echo $ans . PHP_EOL;

Submission Info

Submission Time
Task B - Kleene Inversion
User hideyuk1
Language PHP7 (7.0.15)
Score 300
Code Size 525 Byte
Status AC
Exec Time 436 ms
Memory 4728 KB

Judge Result

Set Name All Sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 24
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_2, testcase_20, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 11 ms 4728 KB
sample_02 AC 9 ms 4604 KB
sample_03 AC 9 ms 4604 KB
testcase_0 AC 9 ms 4604 KB
testcase_1 AC 9 ms 4604 KB
testcase_10 AC 62 ms 4604 KB
testcase_11 AC 35 ms 4604 KB
testcase_12 AC 9 ms 4604 KB
testcase_13 AC 167 ms 4604 KB
testcase_14 AC 18 ms 4604 KB
testcase_15 AC 14 ms 4604 KB
testcase_16 AC 30 ms 4604 KB
testcase_17 AC 112 ms 4604 KB
testcase_18 AC 189 ms 4604 KB
testcase_19 AC 155 ms 4604 KB
testcase_2 AC 9 ms 4604 KB
testcase_20 AC 258 ms 4604 KB
testcase_3 AC 9 ms 4604 KB
testcase_4 AC 9 ms 4604 KB
testcase_5 AC 8 ms 4604 KB
testcase_6 AC 8 ms 4604 KB
testcase_7 AC 405 ms 4604 KB
testcase_8 AC 436 ms 4604 KB
testcase_9 AC 427 ms 4604 KB