Submission #8926124


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11;
#define LL long long
LL ans, now;
int n, m, a[N], cha[N];
int tag[N], add, tong[N];
int main(){
    //freopen("arc077e.in", "r", stdin);
    //freopen("arc077e.out", "w", stdout);
    cin>>n>>m;
    for(int i = 1;i <= n; i++){
        scanf("%d", &a[i]);
        if(i > 1){
            cha[i] = a[i] - a[i-1] + (a[i] - a[i-1] < 0 ? m : 0);
            int x = (a[i] + 2 - cha[i] + m) % m;
            if(x == 0)x += m;
            int y = (a[i] + 1) % m;
            if(y == 0)y += m;
            if(a[i] < cha[i] - 1){
                tag[1]--;
                tong[1] += a[i] - cha[i];
                if(y > 1){
                    tong[y] += cha[i];
                    tag[y]++;
                }
                tong[x]--;
                tag[x]--;
            }
            else{
                tong[x]--;
                tag[x]--;
                if(y > x)tong[y] += cha[i], tag[y]++;
            }
        }
        ans += cha[i];
    }
    now = ans;
    for(int i = 1;i <= m; i++){
        now += add + tong[i];
        add += tag[i];
        ans = min(ans, now);
    }
    cout<<ans<<endl;
    return 0;
}

Submission Info

Submission Time
Task E - guruguru
User ice_heart
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1234 Byte
Status WA
Exec Time 13 ms
Memory 1792 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 15
WA × 7
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 4 ms 640 KB
half1.txt AC 2 ms 640 KB
half2.txt AC 6 ms 896 KB
half3.txt AC 9 ms 896 KB
half4.txt AC 10 ms 1152 KB
min_m.txt WA 1 ms 256 KB
min_n.txt AC 1 ms 256 KB
mx0.txt WA 13 ms 1792 KB
mx1.txt WA 13 ms 1792 KB
mx2.txt WA 12 ms 1792 KB
rnd0.txt AC 1 ms 256 KB
rnd1.txt AC 1 ms 256 KB
rnd2.txt AC 2 ms 384 KB
rnd3.txt AC 3 ms 512 KB
rnd4.txt WA 9 ms 896 KB
rnd5.txt WA 2 ms 256 KB
rnd6.txt AC 1 ms 256 KB
rnd7.txt AC 1 ms 512 KB
rnd8.txt AC 2 ms 384 KB
rnd9.txt AC 1 ms 256 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB