QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#311626 | #6134. Soldier Game | yyyyxh | WA | 426ms | 12432kb | C++23 | 1.7kb | 2024-01-22 16:21:15 | 2024-01-22 16:21:15 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#define lc (p<<1)
#define rc (p<<1|1)
using namespace std;
int read(){
char c=getchar();int x=0;bool f=0;
while(c<48||c>57) f|=(c=='-'),c=getchar();
do x=(x<<1)+(x<<3)+(c^48),c=getchar();
while(c>=48&&c<=57);
if(f) return -x;
return x;
}
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100003;
struct Mat{
ll f[2][2];
friend Mat operator*(const Mat A,const Mat B){
Mat C;
C.f[0][0]=min(max(A.f[0][0],B.f[0][0]),max(A.f[0][1],B.f[1][0]));
C.f[0][1]=min(max(A.f[0][0],B.f[0][1]),max(A.f[0][1],B.f[1][1]));
C.f[1][0]=min(max(A.f[1][0],B.f[0][0]),max(A.f[1][1],B.f[1][0]));
C.f[1][1]=min(max(A.f[1][0],B.f[0][1]),max(A.f[1][1],B.f[1][1]));
return C;
}
void init(){f[0][0]=f[1][1]=f[1][0]=INF;f[0][1]=0;}
}sg[N<<2];
struct node{
int w,p,t;
friend bool operator<(const node a,const node b){
return a.w>b.w;
}
}s[N<<1];
int n,rk;
int a[N];
void build(int p=1,int l=1,int r=n){
if(l==r) return sg[p].init();
int mid=(l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
sg[p]=sg[lc]*sg[rc];
}
void update(node x,int p=1,int l=1,int r=n){
if(l==r){sg[p].f[x.t][0]=x.w;return;}
int mid=(l+r)>>1;
if(x.p<=mid) update(x,lc,l,mid);
else update(x,rc,mid+1,r);
sg[p]=sg[lc]*sg[rc];
}
void solve(){
n=read();rk=0;
for(int i=1;i<=n;++i){
a[i]=read();
s[++rk]=(node){a[i],i,0};
if(i>1) s[++rk]=(node){a[i]+a[i-1],i,1};
}
build();sort(s+1,s+rk+1);
ll mn=INF;
for(int i=1;i<=rk;++i){
update(s[i]);
mn=min(mn,max(sg[1].f[0][0],sg[1].f[0][1])-s[i].w);
}
printf("%lld\n",mn);
}
int main(){
int tc=read();
while(tc--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1472kb
input:
3 5 -1 4 2 1 1 4 1 3 2 4 1 7
output:
1 2 0
result:
ok 3 number(s): "1 2 0"
Test #2:
score: -100
Wrong Answer
time: 426ms
memory: 12432kb
input:
10010 1 1000000000 1 -1000000000 2 1000000000 -1000000000 4 1000000000 1000000000 -1000000000 -1000000000 3 100 -100 100 16 -17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32 7 -95 -26 63 -55 -19 77 -100 17 -100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1 11 99 10 -100 3 32 2 -26...
output:
0 1000000000 1000000000 2000000000 100 135 153 181 189 90 100 164 176 0 147 135 152 100 200 131 134 76 136 999973319 79 171 146 18 183 82 176 105 200 135 103 109 119 126 158 189 70 21 38 999867614 188 161 100 163 116 200 100 101 200 94 23 183 155 98 183 107 139 65 183 999910622 126 153 168 194 96 10...
result:
wrong answer 2nd numbers differ - expected: '0', found: '1000000000'