Submission #8926472
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;
LL tag[N], add, tong[N], a[N], cha[N];
int main(){
//freopen("arc077e.in", "r", stdin);
//freopen("arc077e.out", "w", stdout);
cin>>n>>m;
for(int i = 1;i <= n; i++){
scanf("%lld", &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
2019-12-12 23:31:33+0900
Task
E - guruguru
User
ice_heart
Language
C++14 (GCC 5.4.1)
Score
700
Code Size
1402 Byte
Status
AC
Exec Time
13 ms
Memory
3328 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:13:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &a[i]);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
700 / 700
Status
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
AC
4 ms
896 KB
half1.txt
AC
3 ms
896 KB
half2.txt
AC
6 ms
1408 KB
half3.txt
AC
9 ms
1664 KB
half4.txt
AC
10 ms
2048 KB
min_m.txt
AC
1 ms
256 KB
min_n.txt
AC
2 ms
256 KB
mx0.txt
AC
13 ms
3328 KB
mx1.txt
AC
13 ms
3328 KB
mx2.txt
AC
13 ms
3328 KB
rnd0.txt
AC
1 ms
256 KB
rnd1.txt
AC
1 ms
256 KB
rnd2.txt
AC
2 ms
512 KB
rnd3.txt
AC
3 ms
640 KB
rnd4.txt
AC
9 ms
1536 KB
rnd5.txt
AC
2 ms
256 KB
rnd6.txt
AC
1 ms
256 KB
rnd7.txt
AC
2 ms
640 KB
rnd8.txt
AC
2 ms
512 KB
rnd9.txt
AC
1 ms
256 KB
sample1.txt
AC
1 ms
256 KB
sample2.txt
AC
1 ms
256 KB