QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#114252 | #5980. River Flow | Kindred | 27 ✓ | 5ms | 3692kb | C++14 | 1.2kb | 2023-06-21 18:49:23 | 2023-06-21 18:49:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N = 5010;
inline LL read()
{
LL p=0; LL f=1; char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
return p*f;
}
LL n,d,a[N],h[N];
int main()
{
LL t = read();
for(LL Tcase=1;Tcase<=t;Tcase++)
{
printf("Case #%lld: ",Tcase);
n = read(); d = read(); d<<=1; bool bk = 1;
LL sum = 0; for(LL i=1;i<=n;i++) a[i] = read();
for(LL i=1;i<=n;i++) for(LL j=i;j<=n;j+=d) if(a[i] != a[j]){bk = 0;}
n = d; h[1] = a[1] - a[n]; for(LL i=2;i<=n;i++) h[i] = a[i] - a[i-1];
sum = 0; for(int i=1;i<=n;i++) sum += a[i];
if(!bk){printf("CHEATERS!\n"); continue;}
LL ans = 0;
for(LL i=d/2;i>=1;i>>=1)
{
for(LL j=1;j<=i;j++)
{
LL s = abs(h[j] - h[j+i]);
if(s&1){bk = 0; break;}
else
{
if(h[j] < h[j+i]) h[j] += s/2,h[j+i] -= s/2;
else h[j] -= s/2,h[j+i] += s/2;
ans+=s/2; sum -= s/2 * n/2;
}
}
if(!bk) break;
}
if(!bk || sum < 0){printf("CHEATERS!\n"); continue;}
else printf("%lld\n",ans);
}
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3620kb
input:
50 48 16 2 2 2 3 3 1 1 2 2 1 1 2 2 3 3 4 4 4 4 5 5 3 3 4 4 1 1 2 2 1 1 2 2 2 2 3 3 1 1 2 2 1 1 2 2 3 3 4 24 2 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 2 41 8 3 2 2 1 1 5 5 4 4 3 3 2 2 4 4 3 3 2 2 1 1 5 5 4 4 3 3 2 2 4 4 3 3 2 2 1 1 5 5 4 4 48 8 3 3 2 3 4 4 5 5 5 5 4 3 2 2 3 3 3 3 2 3 4 4 5 5 5 ...
output:
Case #1: 5 Case #2: 3 Case #3: 4 Case #4: 3 Case #5: 2 Case #6: 5 Case #7: 0 Case #8: 2 Case #9: 6 Case #10: 4 Case #11: 4 Case #12: 4 Case #13: CHEATERS! Case #14: 5 Case #15: 6 Case #16: 4 Case #17: 3 Case #18: CHEATERS! Case #19: 4 Case #20: 6 Case #21: 1 Case #22: CHEATERS! Case #23: CHEATERS! C...
result:
ok 50 lines
Subtask #2:
score: 17
Accepted
Test #2:
score: 17
Accepted
time: 5ms
memory: 3692kb
input:
50 36 8 4 3 3 4 4 4 4 4 4 1 1 4 4 4 4 4 4 3 3 4 4 4 4 4 4 1 1 4 4 4 4 4 4 3 3 4 4160 256 939 964 941 954 947 954 926 950 954 962 954 944 927 940 899 904 917 935 914 926 922 942 920 954 943 945 931 936 932 951 915 932 949 966 950 957 955 960 932 958 957 955 944 944 932 938 900 911 932 952 927 930 928...
output:
Case #1: 5 Case #2: 545 Case #3: 836 Case #4: 617 Case #5: 582 Case #6: 401 Case #7: CHEATERS! Case #8: 0 Case #9: 0 Case #10: 232 Case #11: 142 Case #12: 83 Case #13: 310 Case #14: CHEATERS! Case #15: 2 Case #16: CHEATERS! Case #17: 776 Case #18: 355 Case #19: 329 Case #20: 496 Case #21: CHEATERS! ...
result:
ok 50 lines
Extra Test:
score: 0
Extra Test Passed