Submission #3414357


Source Code Expand

#include <algorithm>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n, m; cin >> n >> m;
    int a[2*n]; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; }
    for (int i = 0; i < n; i++) a[i+n] = a[i];
    long long b[2*m] = {};
    for (int i = 1; i < n; i++) {
        int x = a[i-1], y = a[i];
        if (y < x) y += n;
        if (y == x + 1) continue;
        b[x+2]++;
        b[y+1] -= (y-x-1)+1;
        b[y+2] += y-x-1;
    }
    // for (int i = 0; i < 2*m; i++) cout << b[i] << ' '; cout << endl;
    for (int i = 1; i < 2*m; i++) b[i] += b[i-1];
    // for (int i = 0; i < 2*m; i++) cout << b[i] << ' '; cout << endl;
    for (int i = 1; i < 2*m; i++) b[i] += b[i-1];
    // for (int i = 0; i < 2*m; i++) cout << b[i] << ' '; cout << endl;
    for (int i = 0; i < m; i++) b[i] += b[i+m];
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        int x = a[i-1], y = a[i];
        if (x < y) ans += y - x;
        else ans += m + y - x;
    }
    cout << ans - *max_element(b, b+m) << endl;
}

Submission Info

Submission Time
Task E - guruguru
User kozima
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1080 Byte
Status RE
Exec Time 101 ms
Memory 2560 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 5
WA × 15
RE × 2
Set Name Test Cases
Sample sample1.txt, sample2.txt
All half0.txt, half1.txt, half2.txt, half3.txt, half4.txt, min_m.txt, min_n.txt, mx0.txt, mx1.txt, mx2.txt, rnd0.txt, rnd1.txt, rnd2.txt, rnd3.txt, rnd4.txt, rnd5.txt, rnd6.txt, rnd7.txt, rnd8.txt, rnd9.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
half0.txt WA 11 ms 1280 KB
half1.txt WA 6 ms 1920 KB
half2.txt WA 18 ms 1792 KB
half3.txt WA 27 ms 1536 KB
half4.txt WA 29 ms 2304 KB
min_m.txt WA 1 ms 256 KB
min_n.txt WA 3 ms 1792 KB
mx0.txt AC 38 ms 2560 KB
mx1.txt AC 38 ms 2560 KB
mx2.txt AC 38 ms 2560 KB
rnd0.txt WA 2 ms 640 KB
rnd1.txt WA 1 ms 256 KB
rnd2.txt WA 3 ms 512 KB
rnd3.txt RE 101 ms 512 KB
rnd4.txt WA 22 ms 896 KB
rnd5.txt WA 2 ms 256 KB
rnd6.txt WA 1 ms 256 KB
rnd7.txt WA 2 ms 640 KB
rnd8.txt RE 99 ms 384 KB
rnd9.txt WA 1 ms 384 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB