QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#144518 | #6134. Soldier Game | PhantomThreshold# | WA | 1541ms | 30548kb | C++20 | 2.4kb | 2023-08-21 16:52:47 | 2023-08-21 16:52:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct node
{
int l,r;
int c[2][2];//l-1+d~r-d connected
node *lson,*rson;
}*root,pool[233333];
int top;
node *build(int l,int r)
{
node *tmp=&pool[top++];
tmp->l=l;tmp->r=r;
tmp->c[0][0]=tmp->c[0][1]=tmp->c[1][0]=tmp->c[1][1]=0;
if(l==r)tmp->c[0][1]=tmp->c[1][0]=1;
if(l==r-1)tmp->c[1][1]=1;
tmp->lson=tmp->rson=nullptr;
if(l!=r)
{
int mid=(l+r)/2;
tmp->lson=build(l,mid);
tmp->rson=build(mid+1,r);
}
return tmp;
}
vector<vector<int>> E;
void upd(node *cur,int pos)
{
cur->c[0][0]=cur->c[0][1]=cur->c[1][0]=cur->c[1][1]=0;
if(cur->l==cur->r)cur->c[0][1]=cur->c[1][0]=1;
if(cur->l==cur->r-1)cur->c[1][1]=1;
if(cur->l==cur->r)
{
if(E[cur->l-1][1])
cur->c[0][0]=1;
else
cur->c[0][0]=0;
return;
}
if(cur->l+1==cur->r)
{
if(E[cur->l-1][2])
cur->c[0][0]=1;
else
cur->c[0][0]=0;
}
if(pos<=cur->lson->r)
upd(cur->lson,pos);
else
upd(cur->rson,pos);
for(int i=0;i<=1;i++)
{
for(int j=0;j<=1;j++)
{
cur->c[i][j]|=(cur->lson->c[i][0] and cur->rson->c[0][j] and E[cur->lson->r][1]);
cur->c[i][j]|=(cur->lson->c[i][1] and cur->rson->c[0][j] and E[cur->lson->r-1][2]);
cur->c[i][j]|=(cur->lson->c[i][0] and cur->rson->c[1][j] and E[cur->lson->r][2]);
}
}
}
int query(node *cur){return cur->c[0][0];}
int main()
{
ios_base::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
vector<int> a(n+5);
vector<vector<int>> _(n+5,vector<int>(5));
E.swap(_);
top=0;
root=build(1,n);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
vector<tuple<long long,int,int>> edges;
for(int i=1;i<=n;i++)
{
edges.emplace_back(a[i],i-1,i);
if(i!=n)edges.emplace_back(a[i]+a[i+1],i-1,i+1);
}
sort(edges.begin(),edges.end());
int r=-1;
long long ans=4e9;
for(int l=0;l<n+n-1;l++)
{
while(r<n+n-2 and not query(root))
{
r++;
auto [w,u,v]=edges[r];
E[u][v-u]=1;
// cerr<<"add edge "<<u<<' '<<v-u<<' '<<w<<endl;
upd(root,u);
if(v-u==2)upd(root,u+1);
}
if(query(root))
{
// cerr<<"good "<<l<<' '<<r<<' '<<get<0>(edges[r])-get<0>(edges[l])<<endl;
ans=min(ans,get<0>(edges[r])-get<0>(edges[l]));
}
auto [w,u,v]=edges[l];
E[u][v-u]=0;
// cerr<<"del edge "<<u<<' '<<v-u<<' '<<w<<endl;
upd(root,u);
if(v-u==2)upd(root,u+1);
}
cout<<ans<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3532kb
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: 1541ms
memory: 30548kb
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 0 0 3000000000 4000000000 167 4000000000 238 196 4000000000 4000000000 188 152 0 194 4000000000 201 4000000000 284 4000000000 134 0 4000000000 0 63 232 147 0 4000000000 82 290 105 218 212 103 189 188 193 214 4000000000 4000000000 0 43 4000000000 4000000000 259 0 4000000000 310 4000000000 0 4000000...
result:
wrong answer 4th numbers differ - expected: '2000000000', found: '3000000000'