QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#417562 | #1833. Deleting | Harry27182 | RE | 1ms | 5688kb | C++14 | 1.9kb | 2024-05-22 19:43:24 | 2024-05-22 19:43:24 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int n,ok[4005][4005],x;pair<int,int>p[4000005];ull num[64];
struct Bitset
{
ull val[75];
int get(int x){return (val[x/64]>>(x&63))&1;}
void upd(int x){val[x/64]^=(1llu<<(x&63));}
int _Find_first()
{
for(int i=0;i<=n/64;i++)
{
if(!val[i])continue;
return __builtin_ctzll(val[i])+i*64;
}
return n+1;
}
int _Find_next(int x)
{
int p=x/64,q=x&63;
if(val[p]&num[q])return __builtin_ctzll(val[p]&num[q])+p*64;
for(int i=p+1;i<=n/64;i++)
{
if(!val[i])continue;
return __builtin_ctzll(val[i])+i*64;
}
return n+1;
}
}L[4005],R[4005],nL[4005],nR[4005];
Bitset operator &(Bitset x,Bitset y)
{
Bitset res;
for(int i=0;i<=n/64;i++)res.val[i]=x.val[i]&y.val[i];
return res;
}
void insert(int l,int r)
{
assert(L[l].get(r));
if(l-1>=1&&r+1<=n&&ok[l-1][r+1]&&!L[l-1].get(r+1))
{
L[l-1].upd(r+1);R[r+1].upd(l-1);nL[l-1].upd(r+1);nR[r+1].upd(l-1);
insert(l-1,r+1);
}
Bitset now=R[l-1]&nR[r];
for(int i=now._Find_first();i<=n;i=now._Find_next(i))
{
L[i].upd(r);R[r].upd(i);nL[i].upd(r);nR[r].upd(i);
insert(i,r);
}
now=L[r+1]&nL[l];
for(int i=now._Find_first();i<=n;i=now._Find_next(i))
{
L[l].upd(i);R[i].upd(l);nL[l].upd(i);nR[i].upd(l);
insert(l,i);
}
}
int solve(int l,int r)
{
ok[l][r]=1;
if((l+1==r||L[l+1].get(r-1))&&(!L[l].get(r)))
{
L[l].upd(r);R[r].upd(l);nL[l].upd(r);nR[r].upd(l);
insert(l,r);
}
return L[1].get(n);
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n;
for(int i=0;i<64;i++)
{
for(int j=i+1;j<64;j++)num[i]|=(1llu<<j);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)nL[i].upd(j),nR[i].upd(j);
}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j+=2)cin>>x,p[x]={i,j};
}
for(int i=1;i<=(n/2)*(n/2);i++)
{
if(solve(p[i].first,p[i].second)){cout<<i;return 0;}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5540kb
input:
2 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5688kb
input:
6 2 1 3 4 5 6 7 8 9
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: -100
Runtime Error
input:
10 20 21 2 11 25 3 24 18 8 6 17 7 5 22 4 23 14 15 1 19 16 12 10 13 9