QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177408 | #6191. Hard Problem | PhantomThreshold# | WA | 0ms | 3804kb | C++20 | 889b | 2023-09-12 22:25:20 | 2023-09-12 22:25:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
#define int long long
ios_base::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
vector<int> a(n+5);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
long long ans=0;
int f1=0,f2[2]={0ll,0ll};
for(int i=1;i<=n;i++)
{
// cerr<<"pos "<<i<<' '<<a[i]<<' '<<f1<<' '<<f2[i%2]<<' '<<f2[(i+1)%2]<<endl;
int d2=max(max(a[i]-f1,0ll)-max(a[i+1]-f1-f2[(i+1)%2],0ll),min(max(a[i]-f1,0ll),f2[i%2]));
int d1=max(min(max(a[i]-f2[i%2],0ll),max(a[i+1]-f2[(i+1)%2],0ll)),min(a[i],f1));
if(d2<=f2[i%2])f2[i%2]=d2;
else
{
// cerr<<"type 2 add "<<d2-f2[i%2]<<endl;
ans+=d2-f2[i%2],f2[i%2]=d2;
}
if(d1<=f1)f1=d1;
else
{
// cerr<<"type 1 add "<<d1-f1<<endl;
ans+=d1-f1,f1=d1;
}
}
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
3 5 2 1 2 1 2 8 1000000000 1000000000 0 1000000000 1000000000 0 1000000000 1000000000 13 1 1 4 5 1 4 1 9 1 9 8 1 0
output:
2 3000000000 19
result:
ok 3 number(s): "2 3000000000 19"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3804kb
input:
5 50 3 4 10 2 9 1 2 1 3 8 8 4 0 7 5 4 4 3 9 7 4 1 3 5 2 1 5 10 1 5 9 2 2 4 9 10 10 0 1 0 6 2 1 4 4 1 0 10 9 8 50 447 695 336 2 590 444 493 390 62 255 475 342 518 539 780 636 811 813 231 990 804 778 742 627 555 625 211 843 200 638 340 172 99 866 189 125 51 406 294 409 158 126 489 402 256 433 121 546 ...
output:
78 5567 601370 82513477 7608823572
result:
wrong answer 1st numbers differ - expected: '77', found: '78'