QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797298 | #8952. 解谜游戏 | misfits | 51.315 | 35ms | 8060kb | C++14 | 4.2kb | 2024-12-02 20:27:12 | 2024-12-02 20:27:12 |
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 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;vector<LL>P,ans;
#define PL pair<LL,LL>
#define mp make_pair
#define fir first
#define sec second
inline LL GET(vector<PL>vc){
vector<LL>p=P;
for(auto u:vc){
// cout<<" -> u.fir = "<<u.fir<<" u.sec = "<<u.sec<<endl;
swap(p[u.fir],p[u.sec]);
}
// cout<<" p : ";for(auto u:p)cout<<u<<" ";cout<<endl;
return query(p);
}
LL X=-1,Y=-1;
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<PL>&vc,LL l,LL r){
vector<PL>tmp;for(LL i=l;i<=r;i++)tmp.pb(vc[i]);
// cout<<" -> l = "<<l<<" r = "<<r<<endl;
LL cnt=GET(tmp);if(!cnt)return ;
// cout<<" -> l = "<<l<<" r = "<<r<<" cnt = "<<cnt<<endl;
if(l==r){
// cout<<" -> vc[l].fir = "<<vc[l].fir<<" P[vc[l].sec] = "<<P[vc[l].sec]<<" vc[l].sec = "<<vc[l].sec<<" P[vc[l].fir] = "<<P[vc[l].fir]<<endl;
if(cnt==1){
if(brute(vc[l].fir,P[vc[l].sec])){
ans[vc[l].fir]=P[vc[l].sec];
X=vc[l].fir;Y=P[vc[l].sec];
// cout<<" -> vc[l].fir = "<<vc[l].fir<<" P[vc[l].sec] = "<<P[vc[l].sec]<<endl;
}
else {
ans[vc[l].sec]=P[vc[l].fir];
X=vc[l].sec;Y=P[vc[l].fir];
// cout<<" -> vc[l].sec = "<<vc[l].sec<<" P[vc[l].fir] = "<<P[vc[l].fir]<<endl;
}
}
else {
// cout<<" -> vc[l].fir = "<<vc[l].fir<<" P[vc[l].sec] = "<<P[vc[l].sec]<<endl;
ans[vc[l].fir]=P[vc[l].sec];
X=vc[l].fir;Y=P[vc[l].sec];
// cout<<" -> vc[l].sec = "<<vc[l].sec<<" P[vc[l].fir] = "<<P[vc[l].fir]<<endl;
ans[vc[l].sec]=P[vc[l].fir];
}
return ;
}
LL mid=(l+r)>>1;
solve(vc,l,mid);solve(vc,mid+1,r);
return ;
}
void play(LL _n_){
n=_n_;if(n==1){check({0});return ;}
P.resize(n);for(LL t=0;t<n;t++)P[t]=t;
while(true){
for(LL t=0;t<n;t++)swap(P[t],P[random(0,(n-1))]);
// cout<<" -> p = ";for(auto u:P)cout<<u<<" ";cout<<endl;
if(!query(P))break;
}
// cout<<" P " ;for(auto u:P)cout<<u<<" ";cout<<endl;
vector<vector<PL>>vc;
if(n&1){
auto tr=[&](LL x){
if(x<1)x+=n;
if(x>n)x-=n;
return x;
};
vc.resize(n);
for(LL t=0;t<n;t++){
vector<PL>p;
for(LL i=1;i<=(n>>1);i++)p.pb(mp(tr((t+1)-i),tr((t+1)+i)));
vc[t]=p;
}
}
else {
auto tr=[&](LL x){
if(x<1)x+=(n-1);
if(x>(n-1))x-=(n-1);
return x;
};
vc.resize(n-1);
for(LL t=0;t<n-1;t++){
vector<PL>p;p.pb(mp(t+1,n));
for(LL i=1;i<(n>>1);i++)p.pb(mp(tr((t+1)-i),tr((t+1)+i)));
vc[t]=p;
}
}
/* for(LL t=0;t<SZ(vc);t++){
cout<<"> t = "<<t<<" vc[t] : ";
for(auto u:vc[t])cout<<" ("<<u.fir<<","<<u.sec<<") ";cout<<endl;
}*/
ans.resize(n);
for(LL t=0;t<SZ(vc);t++){
for(LL i=0;i<SZ(vc[t]);i++){vc[t][i].fir--;vc[t][i].sec--;}
solve(vc[t],0,SZ(vc[t])-1);
}
// cout<<" -> ans : ";for(auto u:ans)cout<<u<<" ";cout<<endl;
check(ans);return ;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 1ms
memory: 3772kb
input:
1 2 816815200
result:
ok accepted: cnt = 2
Test #2:
score: 2
Accepted
time: 0ms
memory: 3812kb
input:
1 3 723182155
result:
ok accepted: cnt = 11
Test #3:
score: 2
Accepted
time: 1ms
memory: 4088kb
input:
1 5 971867682
result:
ok accepted: cnt = 41
Test #4:
score: 2
Accepted
time: 0ms
memory: 4084kb
input:
1 3 887042235
result:
ok accepted: cnt = 36
Test #5:
score: 2
Accepted
time: 1ms
memory: 4092kb
input:
1 3 568659743
result:
ok accepted: cnt = 11
Test #6:
score: 2
Accepted
time: 1ms
memory: 3804kb
input:
1 5 930991667
result:
ok accepted: cnt = 44
Test #7:
score: 2
Accepted
time: 0ms
memory: 3772kb
input:
1 5 185481439
result:
ok accepted: cnt = 25
Test #8:
score: 2
Accepted
time: 0ms
memory: 3812kb
input:
1 5 405685705
result:
ok accepted: cnt = 41
Test #9:
score: 2
Accepted
time: 1ms
memory: 3840kb
input:
1 5 693401039
result:
ok accepted: cnt = 25
Test #10:
score: 2
Accepted
time: 0ms
memory: 3772kb
input:
1 5 570594473
result:
ok accepted: cnt = 38
Subtask #2:
score: 4
Accepted
Test #11:
score: 4
Accepted
time: 0ms
memory: 3880kb
input:
2 2 931107645
result:
ok accepted: cnt = 2
Test #12:
score: 4
Accepted
time: 0ms
memory: 3800kb
input:
2 4 512124670
result:
ok accepted: cnt = 11
Test #13:
score: 4
Accepted
time: 1ms
memory: 3816kb
input:
2 4 793864173
result:
ok accepted: cnt = 6
Test #14:
score: 4
Accepted
time: 0ms
memory: 4088kb
input:
2 7 322910591
result:
ok accepted: cnt = 33
Test #15:
score: 4
Accepted
time: 1ms
memory: 3772kb
input:
2 9 316192686
result:
ok accepted: cnt = 76
Test #16:
score: 4
Accepted
time: 1ms
memory: 4088kb
input:
2 10 350886420
result:
ok accepted: cnt = 71
Test #17:
score: 4
Accepted
time: 0ms
memory: 3860kb
input:
2 10 914937911
result:
ok accepted: cnt = 86
Test #18:
score: 4
Accepted
time: 0ms
memory: 4108kb
input:
2 10 68729974
result:
ok accepted: cnt = 80
Test #19:
score: 4
Accepted
time: 0ms
memory: 4096kb
input:
2 10 15788440
result:
ok accepted: cnt = 70
Test #20:
score: 4
Accepted
time: 0ms
memory: 4096kb
input:
2 10 950846282
result:
ok accepted: cnt = 82
Subtask #3:
score: 6
Accepted
Test #21:
score: 6
Accepted
time: 0ms
memory: 4088kb
input:
3 2 667362636
result:
ok accepted: cnt = 5
Test #22:
score: 6
Accepted
time: 0ms
memory: 3808kb
input:
3 4 890842001
result:
ok accepted: cnt = 11
Test #23:
score: 6
Accepted
time: 0ms
memory: 3808kb
input:
3 3 225277415
result:
ok accepted: cnt = 20
Test #24:
score: 6
Accepted
time: 0ms
memory: 3840kb
input:
3 26 235413642
result:
ok accepted: cnt = 255
Test #25:
score: 6
Accepted
time: 0ms
memory: 3800kb
input:
3 25 139642984
result:
ok accepted: cnt = 224
Test #26:
score: 6
Accepted
time: 1ms
memory: 3836kb
input:
3 30 991911708
result:
ok accepted: cnt = 320
Test #27:
score: 6
Accepted
time: 0ms
memory: 3748kb
input:
3 30 4514256
result:
ok accepted: cnt = 273
Test #28:
score: 6
Accepted
time: 0ms
memory: 3804kb
input:
3 30 157113423
result:
ok accepted: cnt = 286
Test #29:
score: 6
Accepted
time: 0ms
memory: 3800kb
input:
3 30 557648974
result:
ok accepted: cnt = 290
Test #30:
score: 6
Accepted
time: 0ms
memory: 3808kb
input:
3 30 645022468
result:
ok accepted: cnt = 305
Test #31:
score: 6
Accepted
time: 0ms
memory: 4084kb
input:
4 2 427653480
result:
ok accepted: cnt = 5
Test #32:
score: 6
Accepted
time: 0ms
memory: 3836kb
input:
4 3 219860551
result:
ok accepted: cnt = 11
Test #33:
score: 6
Accepted
time: 0ms
memory: 3876kb
input:
4 4 165138325
result:
ok accepted: cnt = 35
Test #34:
score: 6
Accepted
time: 1ms
memory: 3836kb
input:
4 93 525060479
result:
ok accepted: cnt = 1201
Test #35:
score: 6
Accepted
time: 1ms
memory: 3776kb
input:
4 99 829735778
result:
ok accepted: cnt = 1300
Subtask #4:
score: 8
Accepted
Test #36:
score: 8
Accepted
time: 1ms
memory: 3876kb
input:
4 100 6610818
result:
ok accepted: cnt = 1301
Test #37:
score: 8
Accepted
time: 1ms
memory: 3852kb
input:
4 100 653323659
result:
ok accepted: cnt = 1337
Test #38:
score: 8
Accepted
time: 0ms
memory: 3880kb
input:
4 100 268513130
result:
ok accepted: cnt = 1301
Test #39:
score: 8
Accepted
time: 1ms
memory: 3844kb
input:
4 100 479581529
result:
ok accepted: cnt = 1263
Test #40:
score: 8
Accepted
time: 1ms
memory: 3928kb
input:
4 100 119844914
result:
ok accepted: cnt = 1331
Subtask #5:
score: 10
Accepted
Test #41:
score: 10
Accepted
time: 0ms
memory: 3740kb
input:
5 2 527801655
result:
ok accepted: cnt = 2
Test #42:
score: 10
Accepted
time: 0ms
memory: 3792kb
input:
5 5 235665947
result:
ok accepted: cnt = 41
Test #43:
score: 10
Accepted
time: 0ms
memory: 3772kb
input:
5 3 648413779
result:
ok accepted: cnt = 20
Test #44:
score: 10
Accepted
time: 3ms
memory: 4048kb
input:
5 272 737778828
result:
ok accepted: cnt = 4250
Test #45:
score: 10
Accepted
time: 3ms
memory: 4060kb
input:
5 278 173436130
result:
ok accepted: cnt = 4442
Test #46:
score: 10
Accepted
time: 4ms
memory: 4232kb
input:
5 300 997862299
result:
ok accepted: cnt = 4838
Test #47:
score: 10
Accepted
time: 4ms
memory: 4368kb
input:
5 300 764271855
result:
ok accepted: cnt = 4797
Test #48:
score: 10
Accepted
time: 0ms
memory: 4464kb
input:
5 300 428892383
result:
ok accepted: cnt = 4758
Test #49:
score: 10
Accepted
time: 4ms
memory: 4172kb
input:
5 300 166706392
result:
ok accepted: cnt = 4821
Test #50:
score: 10
Accepted
time: 4ms
memory: 4168kb
input:
5 300 843444435
result:
ok accepted: cnt = 4715
Subtask #6:
score: 10
Accepted
Test #51:
score: 10
Accepted
time: 0ms
memory: 4084kb
input:
6 2 183795068
result:
ok accepted: cnt = 2
Test #52:
score: 10
Accepted
time: 0ms
memory: 4092kb
input:
6 5 63668012
result:
ok accepted: cnt = 23
Test #53:
score: 10
Accepted
time: 0ms
memory: 3884kb
input:
6 5 990398365
result:
ok accepted: cnt = 42
Test #54:
score: 10
Accepted
time: 8ms
memory: 4728kb
input:
6 488 942578687
result:
ok accepted: cnt = 8496
Test #55:
score: 10
Accepted
time: 8ms
memory: 4704kb
input:
6 475 915148470
result:
ok accepted: cnt = 8070
Test #56:
score: 10
Accepted
time: 9ms
memory: 5092kb
input:
6 500 736505651
result:
ok accepted: cnt = 8659
Test #57:
score: 10
Accepted
time: 9ms
memory: 4776kb
input:
6 500 352417213
result:
ok accepted: cnt = 8659
Test #58:
score: 10
Accepted
time: 9ms
memory: 4804kb
input:
6 500 80534667
result:
ok accepted: cnt = 8677
Test #59:
score: 10
Accepted
time: 9ms
memory: 4800kb
input:
6 500 811975157
result:
ok accepted: cnt = 8710
Test #60:
score: 10
Accepted
time: 9ms
memory: 5100kb
input:
6 500 471392863
result:
ok accepted: cnt = 8656
Subtask #7:
score: 11.315
Acceptable Answer
Test #61:
score: 60
Accepted
time: 0ms
memory: 4088kb
input:
7 2 412859550
result:
ok accepted: cnt = 2
Test #62:
score: 60
Accepted
time: 0ms
memory: 3800kb
input:
7 4 892225546
result:
ok accepted: cnt = 22
Test #63:
score: 60
Accepted
time: 0ms
memory: 3804kb
input:
7 4 577686541
result:
ok accepted: cnt = 16
Test #64:
score: 17.2875
Acceptable Answer
time: 24ms
memory: 6968kb
input:
7 902 974849567
result:
points 0.288125 partially_correct: cnt = 17085
Test #65:
score: 14.635
Acceptable Answer
time: 30ms
memory: 7288kb
input:
7 939 155203710
result:
points 0.2439166667 partially_correct: cnt = 18146
Test #66:
score: 11.5225
Acceptable Answer
time: 30ms
memory: 7780kb
input:
7 1000 253107507
result:
points 0.1920416667 partially_correct: cnt = 19391
Test #67:
score: 11.625
Acceptable Answer
time: 30ms
memory: 7964kb
input:
7 1000 882029420
result:
points 0.19375 partially_correct: cnt = 19350
Test #68:
score: 11.7175
Acceptable Answer
time: 34ms
memory: 7708kb
input:
7 1000 199421982
result:
points 0.1952916667 partially_correct: cnt = 19313
Test #69:
score: 11.455
Acceptable Answer
time: 34ms
memory: 8052kb
input:
7 1000 749220884
result:
points 0.1909166667 partially_correct: cnt = 19418
Test #70:
score: 11.51
Acceptable Answer
time: 30ms
memory: 7756kb
input:
7 1000 729055050
result:
points 0.1918333333 partially_correct: cnt = 19396
Test #71:
score: 60
Accepted
time: 0ms
memory: 4088kb
input:
7 2 375338281
result:
ok accepted: cnt = 5
Test #72:
score: 60
Accepted
time: 0ms
memory: 3804kb
input:
7 5 914443594
result:
ok accepted: cnt = 27
Test #73:
score: 60
Accepted
time: 0ms
memory: 3996kb
input:
7 5 310479620
result:
ok accepted: cnt = 37
Test #74:
score: 12.6825
Acceptable Answer
time: 32ms
memory: 7916kb
input:
7 982 660842623
result:
points 0.211375 partially_correct: cnt = 18927
Test #75:
score: 12.23
Acceptable Answer
time: 28ms
memory: 7660kb
input:
7 985 92435101
result:
points 0.2038333333 partially_correct: cnt = 19108
Test #76:
score: 11.74
Acceptable Answer
time: 34ms
memory: 7960kb
input:
7 1000 901527471
result:
points 0.1956666667 partially_correct: cnt = 19304
Test #77:
score: 11.7875
Acceptable Answer
time: 34ms
memory: 7780kb
input:
7 1000 891945482
result:
points 0.1964583333 partially_correct: cnt = 19285
Test #78:
score: 11.7875
Acceptable Answer
time: 30ms
memory: 7772kb
input:
7 1000 461988571
result:
points 0.1964583333 partially_correct: cnt = 19285
Test #79:
score: 11.5625
Acceptable Answer
time: 30ms
memory: 7760kb
input:
7 1000 588921486
result:
points 0.1927083333 partially_correct: cnt = 19375
Test #80:
score: 11.73
Acceptable Answer
time: 34ms
memory: 7780kb
input:
7 1000 819181186
result:
points 0.1955 partially_correct: cnt = 19308
Test #81:
score: 60
Accepted
time: 1ms
memory: 4088kb
input:
7 2 509390821
result:
ok accepted: cnt = 2
Test #82:
score: 60
Accepted
time: 0ms
memory: 3836kb
input:
7 3 932973010
result:
ok accepted: cnt = 39
Test #83:
score: 60
Accepted
time: 0ms
memory: 3744kb
input:
7 3 704198002
result:
ok accepted: cnt = 28
Test #84:
score: 11.71
Acceptable Answer
time: 34ms
memory: 7740kb
input:
7 996 844688748
result:
points 0.1951666667 partially_correct: cnt = 19316
Test #85:
score: 15.165
Acceptable Answer
time: 30ms
memory: 7260kb
input:
7 935 983758765
result:
points 0.25275 partially_correct: cnt = 17934
Test #86:
score: 11.66
Acceptable Answer
time: 35ms
memory: 8048kb
input:
7 1000 560957955
result:
points 0.1943333333 partially_correct: cnt = 19336
Test #87:
score: 11.7125
Acceptable Answer
time: 34ms
memory: 8060kb
input:
7 1000 381616996
result:
points 0.1952083333 partially_correct: cnt = 19315
Test #88:
score: 11.7975
Acceptable Answer
time: 27ms
memory: 7824kb
input:
7 1000 607168013
result:
points 0.196625 partially_correct: cnt = 19281
Test #89:
score: 11.385
Acceptable Answer
time: 34ms
memory: 7776kb
input:
7 1000 755432541
result:
points 0.18975 partially_correct: cnt = 19446
Test #90:
score: 11.8525
Acceptable Answer
time: 34ms
memory: 7824kb
input:
7 1000 675700852
result:
points 0.1975416667 partially_correct: cnt = 19259
Test #91:
score: 60
Accepted
time: 1ms
memory: 4092kb
input:
7 2 91873452
result:
ok accepted: cnt = 2
Test #92:
score: 60
Accepted
time: 1ms
memory: 3804kb
input:
7 4 336570576
result:
ok accepted: cnt = 23
Test #93:
score: 60
Accepted
time: 0ms
memory: 3864kb
input:
7 4 617201184
result:
ok accepted: cnt = 19
Test #94:
score: 16.61
Acceptable Answer
time: 28ms
memory: 7240kb
input:
7 904 396880646
result:
points 0.2768333333 partially_correct: cnt = 17356
Test #95:
score: 16.835
Acceptable Answer
time: 29ms
memory: 7052kb
input:
7 906 970970547
result:
points 0.2805833333 partially_correct: cnt = 17266
Test #96:
score: 11.315
Acceptable Answer
time: 34ms
memory: 7768kb
input:
7 1000 960558936
result:
points 0.1885833333 partially_correct: cnt = 19474
Test #97:
score: 11.9375
Acceptable Answer
time: 34ms
memory: 8048kb
input:
7 1000 238446836
result:
points 0.1989583333 partially_correct: cnt = 19225
Test #98:
score: 11.4025
Acceptable Answer
time: 30ms
memory: 8052kb
input:
7 1000 897094536
result:
points 0.1900416667 partially_correct: cnt = 19439
Test #99:
score: 11.78
Acceptable Answer
time: 30ms
memory: 7764kb
input:
7 1000 820891454
result:
points 0.1963333333 partially_correct: cnt = 19288
Test #100:
score: 11.53
Acceptable Answer
time: 34ms
memory: 7736kb
input:
7 1000 586475353
result:
points 0.1921666667 partially_correct: cnt = 19388