QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#793214 | #8952. 解谜游戏 | misfits# | 40 | 43ms | 4308kb | C++14 | 4.0kb | 2024-11-29 17:39:45 | 2024-11-29 17:39:49 |
Judging History
answer
#include<bits/stdc++.h>
#include "puzzle.h"
#define LL int
#define SZ(x) ((LL)(x.size()))
#define all(x) (x).begin(),(x).end()
using namespace std;
/*inline LL read(){
LL q=0,w=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();}
return q*w;
}
void write(LL x){
if(x<0){putchar('-');x=(-x);}
if(x>9)write(x/10);
putchar('0'+x%10);
}
inline void writeln(LL x){write(x);puts("");}
inline void writecs(LL x){write(x);putchar(' ');}*/
inline void dmin(LL &x,LL y){if(x>y)x=y;return ;}
inline void dmax(LL &x,LL y){if(x<y)x=y;return ;}
#define cout cerr
#define pb push_back
namespace GenHelper{
#define ull unsigned long long
ull seed=19260817ull;
inline void Get(){seed^=(seed<<7);seed^=(seed>>11);seed^=(seed<<13);}
inline ull Rand(){Get();return (seed^(seed<<32ull));}
}using GenHelper::Rand;
inline LL random(LL l,LL r){return (Rand()%(r-l+1)+l);}
const LL N = 1000+95 ;
LL n;bitset<N>p,q;LL ans[N],X=-1,Y=-1,TEMP;
//(X,Y) 表示一组已经找到的匹配
inline void link(LL x,LL y){//当前确定了 p[x]=y
p[x]=0;q[y]=0;ans[x]=y;
if(X==-1){X=x;Y=y;}
TEMP++;return ;
}
vector<LL>__GET(vector<LL>&a,vector<LL>&b){
vector<LL>p(n);
for(LL i=0;i<n;i++)p[i]=ans[i];
for(LL i=0;i<SZ(a);i++)p[a[i]]=b[i];
for(LL i=0;i<n;i++)assert(p[i]!=-1);
return p;
}
inline LL GET(vector<LL>&a,vector<LL>&b){
vector<LL>p=__GET(a,b);
return query(p);
}
inline bool __brute(LL x,LL y){//极其暴力的判断单点的 p[x] 是否等于 y ,错误率 0.0101 .
for(LL TC=1;TC<=20;TC++){
vector<LL>p(n);for(LL i=0;i<n;i++)p[i]=i;
for(LL i=0;i<n;i++)swap(p[i],p[random(0,(n-1))]);
for(LL i=0;i<n;i++)if(p[i]==y){swap(p[x],p[i]);break;}
if(query(p)==0)return 0;
}
return 1;
}
inline bool brute(LL x,LL y){//判断单点 p[x] 是否等于 y
if(X==-1)return __brute(x,y);
//用一组正确的匹配强行拆解掉原有匹配
vector<LL>p(n);for(LL i=0;i<n;i++)p[i]=i;
for(LL i=0;i<n;i++)swap(p[i],p[random(0,(n-1))]);
for(LL i=0;i<n;i++)if(p[i]==Y){swap(p[X],p[i]);break;}
for(LL i=0;i<n;i++)if(p[i]==y){swap(p[x],p[i]);break;}
LL k=query(p);swap(p[x],p[X]);LL _k=query(p);
return ((k==_k+2)?(1):(0));
}
void solve(vector<LL>a,vector<LL>b,LL l,LL r,LL k){
if(l==r){link(a[l],b[l]);return ;}
LL mid=(l+r)>>1;
if(l==mid){
assert((r-l+1)==2);
vector<LL>c=b;swap(c[l],c[r]);
LL _k=GET(a,c);if(k==_k)return ;//如果相等只有一种可能,那就是这两个元素都不是正确的匹配
if(k<_k){swap(b,c);swap(k,_k);}//此时(b,k)必然存在至少一组合法正确匹配
if(k==_k+2){link(a[l],b[l]);link(a[r],b[r]);return ;}//此时找到了两组正确的匹配
if(brute(a[l],b[l])){link(a[l],b[l]);}
else {link(a[r],b[r]);}
return ;
}
if((r-l+1)<=4){//(mid-l+1)<=2
vector<LL>vc_a={l,l+1},vc_b={l,l+1};
if(random(0,1))swap(vc_a[0],vc_a[1]);
if(random(0,1))swap(vc_b[0],vc_b[1]);
for(auto x:vc_a)
for(auto y:vc_b)if(brute(a[x],b[y])){link(a[x],b[y]);return ;}
solve(a,b,mid+1,r,k);return ;
}
for(LL TC=1;TC<=6;TC++){
vector<LL>c=b;
while(true){
for(LL i=l;i<=mid;i++)swap(c[i],c[random(l,mid)]);
LL fl=0;for(LL i=l;i<=mid;i++)if(b[i]!=c[i]){fl=1;break;}
if(fl)break;
}
LL _k=GET(a,c);
if(k>_k){solve(a,b,l,mid,k);return ;}
if(k<_k){solve(a,c,l,mid,_k);return ;}
}
solve(a,b,mid+1,r,k);
return ;
}
void play(LL _n_){
n=_n_;for(LL t=0;t<n;t++){p[t]=q[t]=1;ans[t]=-1;}
while(true){
vector<LL>a,b;
for(LL t=0;t<n;t++){
if(p[t])a.pb(t);
if(q[t])b.pb(t);
}
assert(SZ(a)==SZ(b));if(!SZ(a))break;
LL len=SZ(a)-1;if(!len){ans[a[0]]=b[0];break;}
for(LL t=0;t<=len;t++)swap(b[t],b[random(0,len)]);
LL k=GET(a,b);
if(k>TEMP)solve(a,b,0,len,k);
}
vector<LL>p(n);
for(LL i=0;i<n;i++){p[i]=ans[i];assert(ans[i]!=-1);}
check(p);return ;
}
/*
my test data:
4
2 3 0 1
*/
詳細信息
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 0ms
memory: 3784kb
input:
1 2 816815200
result:
ok accepted: cnt = 5
Test #2:
score: 2
Accepted
time: 0ms
memory: 3736kb
input:
1 3 723182155
result:
ok accepted: cnt = 25
Test #3:
score: 2
Accepted
time: 0ms
memory: 4080kb
input:
1 5 971867682
result:
ok accepted: cnt = 37
Test #4:
score: 2
Accepted
time: 0ms
memory: 4072kb
input:
1 3 887042235
result:
ok accepted: cnt = 24
Test #5:
score: 2
Accepted
time: 0ms
memory: 4068kb
input:
1 3 568659743
result:
ok accepted: cnt = 25
Test #6:
score: 2
Accepted
time: 0ms
memory: 4072kb
input:
1 5 930991667
result:
ok accepted: cnt = 43
Test #7:
score: 2
Accepted
time: 0ms
memory: 3976kb
input:
1 5 185481439
result:
ok accepted: cnt = 19
Test #8:
score: 2
Accepted
time: 0ms
memory: 3812kb
input:
1 5 405685705
result:
ok accepted: cnt = 37
Test #9:
score: 2
Accepted
time: 0ms
memory: 4080kb
input:
1 5 693401039
result:
ok accepted: cnt = 52
Test #10:
score: 2
Accepted
time: 0ms
memory: 4084kb
input:
1 5 570594473
result:
ok accepted: cnt = 41
Subtask #2:
score: 4
Accepted
Test #11:
score: 4
Accepted
time: 0ms
memory: 3792kb
input:
2 2 931107645
result:
ok accepted: cnt = 5
Test #12:
score: 4
Accepted
time: 0ms
memory: 3808kb
input:
2 4 512124670
result:
ok accepted: cnt = 29
Test #13:
score: 4
Accepted
time: 0ms
memory: 3804kb
input:
2 4 793864173
result:
ok accepted: cnt = 34
Test #14:
score: 4
Accepted
time: 0ms
memory: 3740kb
input:
2 7 322910591
result:
ok accepted: cnt = 47
Test #15:
score: 4
Accepted
time: 0ms
memory: 4068kb
input:
2 9 316192686
result:
ok accepted: cnt = 79
Test #16:
score: 4
Accepted
time: 0ms
memory: 3876kb
input:
2 10 350886420
result:
ok accepted: cnt = 77
Test #17:
score: 4
Accepted
time: 0ms
memory: 4068kb
input:
2 10 914937911
result:
ok accepted: cnt = 74
Test #18:
score: 4
Accepted
time: 0ms
memory: 4088kb
input:
2 10 68729974
result:
ok accepted: cnt = 80
Test #19:
score: 4
Accepted
time: 0ms
memory: 3804kb
input:
2 10 15788440
result:
ok accepted: cnt = 70
Test #20:
score: 4
Accepted
time: 0ms
memory: 3812kb
input:
2 10 950846282
result:
ok accepted: cnt = 99
Subtask #3:
score: 6
Accepted
Test #21:
score: 6
Accepted
time: 0ms
memory: 3784kb
input:
3 2 667362636
result:
ok accepted: cnt = 2
Test #22:
score: 6
Accepted
time: 0ms
memory: 3736kb
input:
3 4 890842001
result:
ok accepted: cnt = 29
Test #23:
score: 6
Accepted
time: 0ms
memory: 3972kb
input:
3 3 225277415
result:
ok accepted: cnt = 26
Test #24:
score: 6
Accepted
time: 0ms
memory: 3792kb
input:
3 26 235413642
result:
ok accepted: cnt = 284
Test #25:
score: 6
Accepted
time: 0ms
memory: 3820kb
input:
3 25 139642984
result:
ok accepted: cnt = 278
Test #26:
score: 6
Accepted
time: 0ms
memory: 3872kb
input:
3 30 991911708
result:
ok accepted: cnt = 354
Test #27:
score: 6
Accepted
time: 1ms
memory: 3880kb
input:
3 30 4514256
result:
ok accepted: cnt = 323
Test #28:
score: 6
Accepted
time: 0ms
memory: 3744kb
input:
3 30 157113423
result:
ok accepted: cnt = 356
Test #29:
score: 6
Accepted
time: 1ms
memory: 3796kb
input:
3 30 557648974
result:
ok accepted: cnt = 371
Test #30:
score: 6
Accepted
time: 0ms
memory: 3812kb
input:
3 30 645022468
result:
ok accepted: cnt = 337
Test #31:
score: 6
Accepted
time: 0ms
memory: 3808kb
input:
4 2 427653480
result:
ok accepted: cnt = 2
Test #32:
score: 6
Accepted
time: 0ms
memory: 4072kb
input:
4 3 219860551
result:
ok accepted: cnt = 25
Test #33:
score: 6
Accepted
time: 0ms
memory: 3808kb
input:
4 4 165138325
result:
ok accepted: cnt = 31
Test #34:
score: 6
Accepted
time: 0ms
memory: 3912kb
input:
4 93 525060479
result:
ok accepted: cnt = 1553
Test #35:
score: 6
Accepted
time: 1ms
memory: 3820kb
input:
4 99 829735778
result:
ok accepted: cnt = 1622
Subtask #4:
score: 8
Accepted
Test #36:
score: 8
Accepted
time: 1ms
memory: 3824kb
input:
4 100 6610818
result:
ok accepted: cnt = 1698
Test #37:
score: 8
Accepted
time: 1ms
memory: 3912kb
input:
4 100 653323659
result:
ok accepted: cnt = 1657
Test #38:
score: 8
Accepted
time: 1ms
memory: 3824kb
input:
4 100 268513130
result:
ok accepted: cnt = 1672
Test #39:
score: 8
Accepted
time: 0ms
memory: 3852kb
input:
4 100 479581529
result:
ok accepted: cnt = 1704
Test #40:
score: 8
Accepted
time: 1ms
memory: 3824kb
input:
4 100 119844914
result:
ok accepted: cnt = 1761
Subtask #5:
score: 10
Accepted
Test #41:
score: 10
Accepted
time: 0ms
memory: 3736kb
input:
5 2 527801655
result:
ok accepted: cnt = 5
Test #42:
score: 10
Accepted
time: 0ms
memory: 3784kb
input:
5 5 235665947
result:
ok accepted: cnt = 41
Test #43:
score: 10
Accepted
time: 0ms
memory: 3864kb
input:
5 3 648413779
result:
ok accepted: cnt = 26
Test #44:
score: 10
Accepted
time: 5ms
memory: 4116kb
input:
5 272 737778828
result:
ok accepted: cnt = 5631
Test #45:
score: 10
Accepted
time: 6ms
memory: 4024kb
input:
5 278 173436130
result:
ok accepted: cnt = 5873
Test #46:
score: 10
Accepted
time: 6ms
memory: 4044kb
input:
5 300 997862299
result:
ok accepted: cnt = 6575
Test #47:
score: 10
Accepted
time: 6ms
memory: 4100kb
input:
5 300 764271855
result:
ok accepted: cnt = 6357
Test #48:
score: 10
Accepted
time: 6ms
memory: 4040kb
input:
5 300 428892383
result:
ok accepted: cnt = 6421
Test #49:
score: 10
Accepted
time: 6ms
memory: 4040kb
input:
5 300 166706392
result:
ok accepted: cnt = 6582
Test #50:
score: 10
Accepted
time: 6ms
memory: 4024kb
input:
5 300 843444435
result:
ok accepted: cnt = 6564
Subtask #6:
score: 10
Accepted
Test #51:
score: 10
Accepted
time: 0ms
memory: 3788kb
input:
6 2 183795068
result:
ok accepted: cnt = 5
Test #52:
score: 10
Accepted
time: 0ms
memory: 3812kb
input:
6 5 63668012
result:
ok accepted: cnt = 37
Test #53:
score: 10
Accepted
time: 0ms
memory: 3980kb
input:
6 5 990398365
result:
ok accepted: cnt = 41
Test #54:
score: 10
Accepted
time: 15ms
memory: 4308kb
input:
6 488 942578687
result:
ok accepted: cnt = 11505
Test #55:
score: 10
Accepted
time: 15ms
memory: 4048kb
input:
6 475 915148470
result:
ok accepted: cnt = 11436
Test #56:
score: 10
Accepted
time: 16ms
memory: 4016kb
input:
6 500 736505651
result:
ok accepted: cnt = 12072
Test #57:
score: 10
Accepted
time: 16ms
memory: 4016kb
input:
6 500 352417213
result:
ok accepted: cnt = 12119
Test #58:
score: 10
Accepted
time: 16ms
memory: 4116kb
input:
6 500 80534667
result:
ok accepted: cnt = 12185
Test #59:
score: 10
Accepted
time: 16ms
memory: 4028kb
input:
6 500 811975157
result:
ok accepted: cnt = 11996
Test #60:
score: 10
Accepted
time: 16ms
memory: 4040kb
input:
6 500 471392863
result:
ok accepted: cnt = 11885
Subtask #7:
score: 0
Wrong Answer
Test #61:
score: 60
Accepted
time: 0ms
memory: 3972kb
input:
7 2 412859550
result:
ok accepted: cnt = 5
Test #62:
score: 60
Accepted
time: 0ms
memory: 3736kb
input:
7 4 892225546
result:
ok accepted: cnt = 29
Test #63:
score: 60
Accepted
time: 0ms
memory: 3788kb
input:
7 4 577686541
result:
ok accepted: cnt = 35
Test #64:
score: 0
Wrong Answer
time: 43ms
memory: 3792kb
input:
7 902 974849567
result:
wrong answer too_many_queries