Submission #19534502


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int domestic_inversion = 0;
    int foreign_inversion = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            if (a[i] > a[j]) {
                domestic_inversion++;
                foreign_inversion++;
            } else if (a[j] > a[i]) {
                foreign_inversion++;
            }
        }
    }
    ll d = (domestic_inversion * k) % mod;
    ll f = (((k * (k - 1) / 2) % mod) * foreign_inversion) % mod;
    cout << (d + f) % mod << endl;
}

Submission Info

Submission Time
Task B - Kleene Inversion
User tokubi_ayato
Language C++ (GCC 9.2.1)
Score 300
Code Size 746 Byte
Status AC
Exec Time 10 ms
Memory 3612 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 9 ms 3452 KB
sample_02 AC 2 ms 3556 KB
sample_03 AC 2 ms 3480 KB
testcase_0 AC 3 ms 3572 KB
testcase_1 AC 2 ms 3504 KB
testcase_10 AC 3 ms 3416 KB
testcase_11 AC 2 ms 3500 KB
testcase_12 AC 3 ms 3484 KB
testcase_13 AC 8 ms 3408 KB
testcase_14 AC 2 ms 3508 KB
testcase_15 AC 2 ms 3612 KB
testcase_16 AC 3 ms 3560 KB
testcase_17 AC 9 ms 3484 KB
testcase_18 AC 7 ms 3492 KB
testcase_19 AC 7 ms 3528 KB
testcase_2 AC 4 ms 3476 KB
testcase_20 AC 7 ms 3528 KB
testcase_3 AC 2 ms 3552 KB
testcase_4 AC 3 ms 3520 KB
testcase_5 AC 2 ms 3400 KB
testcase_6 AC 3 ms 3412 KB
testcase_7 AC 7 ms 3460 KB
testcase_8 AC 10 ms 3492 KB
testcase_9 AC 9 ms 3524 KB