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
Exec Time 436 ms
Memory 4728 KB

Test Cases

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