Submission #19537699


Source Code Expand

Copy
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
mod = 10**9+7
tenl = []
tenr = []
for j in range(n):
    cnt = 0
    for i in range(j):
        if A[j] < A[i]:
            cnt += 1
    tenl.append(cnt)
    cnt = 0
    for i in range(j+1, n):
        if A[j] < A[i]:
            cnt += 1
    tenr.append(cnt)

ans = 0
for i in range(n):
    ans += (k*(k+1)//2 * tenl[i])%mod + (k*(k-1)//2 * tenr[i])%mod
    ans %= mod
print(ans)

Submission Info

Submission Time
Task B - Kleene Inversion
User omr14t
Language Python (3.8.2)
Score 300
Code Size 471 Byte
Status AC
Exec Time 556 ms
Memory 9208 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 26 ms 8948 KB
sample_02 AC 22 ms 9040 KB
sample_03 AC 18 ms 9048 KB
testcase_0 AC 18 ms 8852 KB
testcase_1 AC 18 ms 8940 KB
testcase_10 AC 90 ms 8968 KB
testcase_11 AC 61 ms 9076 KB
testcase_12 AC 27 ms 8948 KB
testcase_13 AC 231 ms 9004 KB
testcase_14 AC 37 ms 8976 KB
testcase_15 AC 26 ms 8860 KB
testcase_16 AC 55 ms 8980 KB
testcase_17 AC 167 ms 9084 KB
testcase_18 AC 261 ms 8932 KB
testcase_19 AC 217 ms 9044 KB
testcase_2 AC 25 ms 9056 KB
testcase_20 AC 356 ms 8948 KB
testcase_3 AC 19 ms 8940 KB
testcase_4 AC 26 ms 9060 KB
testcase_5 AC 21 ms 8948 KB
testcase_6 AC 18 ms 8944 KB
testcase_7 AC 423 ms 8916 KB
testcase_8 AC 548 ms 9020 KB
testcase_9 AC 556 ms 9208 KB