Submission #8926300


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);
            ans += cha[i];
            if(cha[i] == 1)continue;
            int x = a[i] + 2 - cha[i];
            int y = a[i] + 1;
            if(y > m)y = 1;
            if(x < 0)x += 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]++;
            }
            //printf("i=%d cha=%d x=%d y=%d\n", i, cha[i], x, y);
        }
    }
    now = ans;
    for(int i = 1;i <= m; i++){
        now += add + tong[i];
        add += tag[i];
        ans = min(ans, now);
        //printf("i=%d tong=%d tag=%d now=%d\n", i, tong[i], tag[i], 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 1398 Byte
Status WA
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:9:38: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     freopen("arc077e.in", "r", stdin);
                                      ^
./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
WA × 2
WA × 22
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 1 ms 256 KB
half1.txt WA 1 ms 256 KB
half2.txt WA 1 ms 256 KB
half3.txt WA 1 ms 256 KB
half4.txt WA 1 ms 256 KB
min_m.txt WA 1 ms 256 KB
min_n.txt WA 1 ms 256 KB
mx0.txt WA 1 ms 256 KB
mx1.txt WA 1 ms 256 KB
mx2.txt WA 1 ms 256 KB
rnd0.txt WA 1 ms 256 KB
rnd1.txt WA 1 ms 256 KB
rnd2.txt WA 1 ms 256 KB
rnd3.txt WA 1 ms 256 KB
rnd4.txt WA 1 ms 256 KB
rnd5.txt WA 1 ms 256 KB
rnd6.txt WA 1 ms 256 KB
rnd7.txt WA 1 ms 256 KB
rnd8.txt WA 1 ms 256 KB
rnd9.txt WA 1 ms 256 KB
sample1.txt WA 1 ms 256 KB
sample2.txt WA 1 ms 256 KB