QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605438 | #8952. 解谜游戏 | Xun_xiaoyao | 100 ✓ | 13ms | 4224kb | C++20 | 1.6kb | 2024-10-02 17:15:22 | 2024-10-02 17:15:23 |
Judging History
answer
#include <bits/stdc++.h>
#include "puzzle.h"
using namespace std;
mt19937 zsh(20070610);
typedef pair<int,int> pr;
vector<pr> q;
vector<int> E[1010];
int n,hfn,x,y;
vector<int> ans,tk,rd;
int clc(vector<pr> &q)
{
tk=rd;
for(pr g:q) swap(tk[g.first],tk[g.second]);
return query(tk);
}
void solve(vector<pr> &q,int cnt)
{
if(!cnt) return;
if(q.size()==1)
{
E[q[0].first].push_back(q[0].second);
E[q[0].second].push_back(q[0].first);
return;
}
vector<pr> L,R;int mid=q.size()>>1,tmp;
for(int i=0;i<mid;i++) L.push_back(q[i]);
for(int i=mid,lm=q.size();i<lm;i++) R.push_back(q[i]);
tmp=clc(L);
solve(L,tmp),solve(R,cnt-tmp);
}
bool vis[1010];
int stk[1010],top,ls;
void dfs(int a)
{
vis[a]=true,stk[++top]=a;
for(int v:E[a]) if(!vis[v])
dfs(v);
}
void play(int n)
{
::n=n;
rd.resize(n);
for(int i=0;i<n;i++) rd[i]=i;
if(n<=5)
{
do if(query(rd)==n) return check(rd);
while(next_permutation(rd.begin(),rd.end()));
}
while(1)
{
for(int i=1;i<n;i++) swap(rd[i],rd[zsh()%(i+1)]);
if(!query(rd)) break;
}
hfn=n>>1;
for(int i=0;i<n;i++)
{
vector<pr>().swap(q);
if((n&1)||i<hfn) x=i,y=i+1;
else x=y=i;
while(y>=n) y-=n;
for(int j=0;j<hfn;j++)
{
if(x!=y&&E[x].size()<=1&&E[y].size()<=1)
q.push_back(make_pair(x,y));
x--,y++;
while(x<0) x+=n;while(y>=n) y-=n;
}
solve(q,clc(q));
}
ans=rd;
for(int i=0;i<n;i++) if(!vis[i])
{
top=0;
dfs(i);
tk=ans,ls+=top;
for(int i=2;i<=top;i++) swap(tk[stk[i]],tk[stk[i-1]]);
if(query(tk)==ls) ans=tk;
else for(int i=top;i>1;i--) swap(ans[stk[i]],ans[stk[i-1]]);
}
check(ans);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 0ms
memory: 3852kb
input:
1 2 816815200
result:
ok accepted: cnt = 2
Test #2:
score: 2
Accepted
time: 0ms
memory: 3908kb
input:
1 3 723182155
result:
ok accepted: cnt = 6
Test #3:
score: 2
Accepted
time: 0ms
memory: 3832kb
input:
1 5 971867682
result:
ok accepted: cnt = 96
Test #4:
score: 2
Accepted
time: 0ms
memory: 3892kb
input:
1 3 887042235
result:
ok accepted: cnt = 1
Test #5:
score: 2
Accepted
time: 0ms
memory: 3832kb
input:
1 3 568659743
result:
ok accepted: cnt = 6
Test #6:
score: 2
Accepted
time: 0ms
memory: 3764kb
input:
1 5 930991667
result:
ok accepted: cnt = 53
Test #7:
score: 2
Accepted
time: 0ms
memory: 4044kb
input:
1 5 185481439
result:
ok accepted: cnt = 100
Test #8:
score: 2
Accepted
time: 0ms
memory: 3804kb
input:
1 5 405685705
result:
ok accepted: cnt = 40
Test #9:
score: 2
Accepted
time: 0ms
memory: 4132kb
input:
1 5 693401039
result:
ok accepted: cnt = 86
Test #10:
score: 2
Accepted
time: 0ms
memory: 3912kb
input:
1 5 570594473
result:
ok accepted: cnt = 44
Subtask #2:
score: 4
Accepted
Test #11:
score: 4
Accepted
time: 0ms
memory: 4036kb
input:
2 2 931107645
result:
ok accepted: cnt = 2
Test #12:
score: 4
Accepted
time: 0ms
memory: 4120kb
input:
2 4 512124670
result:
ok accepted: cnt = 13
Test #13:
score: 4
Accepted
time: 0ms
memory: 4120kb
input:
2 4 793864173
result:
ok accepted: cnt = 10
Test #14:
score: 4
Accepted
time: 0ms
memory: 3904kb
input:
2 7 322910591
result:
ok accepted: cnt = 15
Test #15:
score: 4
Accepted
time: 0ms
memory: 3840kb
input:
2 9 316192686
result:
ok accepted: cnt = 25
Test #16:
score: 4
Accepted
time: 0ms
memory: 3844kb
input:
2 10 350886420
result:
ok accepted: cnt = 24
Test #17:
score: 4
Accepted
time: 1ms
memory: 3872kb
input:
2 10 914937911
result:
ok accepted: cnt = 27
Test #18:
score: 4
Accepted
time: 0ms
memory: 3852kb
input:
2 10 68729974
result:
ok accepted: cnt = 24
Test #19:
score: 4
Accepted
time: 0ms
memory: 4040kb
input:
2 10 15788440
result:
ok accepted: cnt = 26
Test #20:
score: 4
Accepted
time: 0ms
memory: 4136kb
input:
2 10 950846282
result:
ok accepted: cnt = 25
Subtask #3:
score: 6
Accepted
Test #21:
score: 6
Accepted
time: 0ms
memory: 3832kb
input:
3 2 667362636
result:
ok accepted: cnt = 1
Test #22:
score: 6
Accepted
time: 0ms
memory: 3804kb
input:
3 4 890842001
result:
ok accepted: cnt = 13
Test #23:
score: 6
Accepted
time: 0ms
memory: 4128kb
input:
3 3 225277415
result:
ok accepted: cnt = 5
Test #24:
score: 6
Accepted
time: 0ms
memory: 3836kb
input:
3 26 235413642
result:
ok accepted: cnt = 93
Test #25:
score: 6
Accepted
time: 0ms
memory: 3856kb
input:
3 25 139642984
result:
ok accepted: cnt = 93
Test #26:
score: 6
Accepted
time: 0ms
memory: 3812kb
input:
3 30 991911708
result:
ok accepted: cnt = 108
Test #27:
score: 6
Accepted
time: 0ms
memory: 3916kb
input:
3 30 4514256
result:
ok accepted: cnt = 97
Test #28:
score: 6
Accepted
time: 0ms
memory: 3924kb
input:
3 30 157113423
result:
ok accepted: cnt = 99
Test #29:
score: 6
Accepted
time: 0ms
memory: 4136kb
input:
3 30 557648974
result:
ok accepted: cnt = 99
Test #30:
score: 6
Accepted
time: 0ms
memory: 3848kb
input:
3 30 645022468
result:
ok accepted: cnt = 100
Test #31:
score: 6
Accepted
time: 0ms
memory: 4032kb
input:
4 2 427653480
result:
ok accepted: cnt = 1
Test #32:
score: 6
Accepted
time: 0ms
memory: 3784kb
input:
4 3 219860551
result:
ok accepted: cnt = 6
Test #33:
score: 6
Accepted
time: 0ms
memory: 4076kb
input:
4 4 165138325
result:
ok accepted: cnt = 7
Test #34:
score: 6
Accepted
time: 0ms
memory: 3844kb
input:
4 93 525060479
result:
ok accepted: cnt = 414
Test #35:
score: 6
Accepted
time: 0ms
memory: 3912kb
input:
4 99 829735778
result:
ok accepted: cnt = 454
Subtask #4:
score: 8
Accepted
Test #36:
score: 8
Accepted
time: 1ms
memory: 3868kb
input:
4 100 6610818
result:
ok accepted: cnt = 491
Test #37:
score: 8
Accepted
time: 1ms
memory: 3848kb
input:
4 100 653323659
result:
ok accepted: cnt = 481
Test #38:
score: 8
Accepted
time: 1ms
memory: 3916kb
input:
4 100 268513130
result:
ok accepted: cnt = 471
Test #39:
score: 8
Accepted
time: 1ms
memory: 3844kb
input:
4 100 479581529
result:
ok accepted: cnt = 484
Test #40:
score: 8
Accepted
time: 1ms
memory: 4060kb
input:
4 100 119844914
result:
ok accepted: cnt = 461
Subtask #5:
score: 10
Accepted
Test #41:
score: 10
Accepted
time: 0ms
memory: 4028kb
input:
5 2 527801655
result:
ok accepted: cnt = 2
Test #42:
score: 10
Accepted
time: 0ms
memory: 3832kb
input:
5 5 235665947
result:
ok accepted: cnt = 25
Test #43:
score: 10
Accepted
time: 0ms
memory: 3844kb
input:
5 3 648413779
result:
ok accepted: cnt = 5
Test #44:
score: 10
Accepted
time: 1ms
memory: 3944kb
input:
5 272 737778828
result:
ok accepted: cnt = 1602
Test #45:
score: 10
Accepted
time: 1ms
memory: 3816kb
input:
5 278 173436130
result:
ok accepted: cnt = 1647
Test #46:
score: 10
Accepted
time: 2ms
memory: 3864kb
input:
5 300 997862299
result:
ok accepted: cnt = 1762
Test #47:
score: 10
Accepted
time: 2ms
memory: 3872kb
input:
5 300 764271855
result:
ok accepted: cnt = 1813
Test #48:
score: 10
Accepted
time: 2ms
memory: 3868kb
input:
5 300 428892383
result:
ok accepted: cnt = 1820
Test #49:
score: 10
Accepted
time: 2ms
memory: 4152kb
input:
5 300 166706392
result:
ok accepted: cnt = 1811
Test #50:
score: 10
Accepted
time: 2ms
memory: 4160kb
input:
5 300 843444435
result:
ok accepted: cnt = 1801
Subtask #6:
score: 10
Accepted
Test #51:
score: 10
Accepted
time: 0ms
memory: 3844kb
input:
6 2 183795068
result:
ok accepted: cnt = 2
Test #52:
score: 10
Accepted
time: 0ms
memory: 4128kb
input:
6 5 63668012
result:
ok accepted: cnt = 66
Test #53:
score: 10
Accepted
time: 0ms
memory: 4128kb
input:
6 5 990398365
result:
ok accepted: cnt = 38
Test #54:
score: 10
Accepted
time: 3ms
memory: 3960kb
input:
6 488 942578687
result:
ok accepted: cnt = 3223
Test #55:
score: 10
Accepted
time: 0ms
memory: 3928kb
input:
6 475 915148470
result:
ok accepted: cnt = 3146
Test #56:
score: 10
Accepted
time: 4ms
memory: 4080kb
input:
6 500 736505651
result:
ok accepted: cnt = 3376
Test #57:
score: 10
Accepted
time: 3ms
memory: 3872kb
input:
6 500 352417213
result:
ok accepted: cnt = 3351
Test #58:
score: 10
Accepted
time: 5ms
memory: 3948kb
input:
6 500 80534667
result:
ok accepted: cnt = 3312
Test #59:
score: 10
Accepted
time: 5ms
memory: 3888kb
input:
6 500 811975157
result:
ok accepted: cnt = 3338
Test #60:
score: 10
Accepted
time: 6ms
memory: 3832kb
input:
6 500 471392863
result:
ok accepted: cnt = 3348
Subtask #7:
score: 60
Accepted
Test #61:
score: 60
Accepted
time: 1ms
memory: 3828kb
input:
7 2 412859550
result:
ok accepted: cnt = 2
Test #62:
score: 60
Accepted
time: 0ms
memory: 3996kb
input:
7 4 892225546
result:
ok accepted: cnt = 17
Test #63:
score: 60
Accepted
time: 0ms
memory: 4132kb
input:
7 4 577686541
result:
ok accepted: cnt = 5
Test #64:
score: 60
Accepted
time: 8ms
memory: 3916kb
input:
7 902 974849567
result:
ok accepted: cnt = 6734
Test #65:
score: 60
Accepted
time: 11ms
memory: 3976kb
input:
7 939 155203710
result:
ok accepted: cnt = 7028
Test #66:
score: 60
Accepted
time: 13ms
memory: 3920kb
input:
7 1000 253107507
result:
ok accepted: cnt = 7622
Test #67:
score: 60
Accepted
time: 13ms
memory: 3940kb
input:
7 1000 882029420
result:
ok accepted: cnt = 7604
Test #68:
score: 60
Accepted
time: 13ms
memory: 3944kb
input:
7 1000 199421982
result:
ok accepted: cnt = 7598
Test #69:
score: 60
Accepted
time: 13ms
memory: 3872kb
input:
7 1000 749220884
result:
ok accepted: cnt = 7621
Test #70:
score: 60
Accepted
time: 13ms
memory: 3916kb
input:
7 1000 729055050
result:
ok accepted: cnt = 7564
Test #71:
score: 60
Accepted
time: 0ms
memory: 3880kb
input:
7 2 375338281
result:
ok accepted: cnt = 1
Test #72:
score: 60
Accepted
time: 0ms
memory: 3908kb
input:
7 5 914443594
result:
ok accepted: cnt = 81
Test #73:
score: 60
Accepted
time: 0ms
memory: 3832kb
input:
7 5 310479620
result:
ok accepted: cnt = 75
Test #74:
score: 60
Accepted
time: 12ms
memory: 4008kb
input:
7 982 660842623
result:
ok accepted: cnt = 7444
Test #75:
score: 60
Accepted
time: 12ms
memory: 4116kb
input:
7 985 92435101
result:
ok accepted: cnt = 7469
Test #76:
score: 60
Accepted
time: 13ms
memory: 4212kb
input:
7 1000 901527471
result:
ok accepted: cnt = 7697
Test #77:
score: 60
Accepted
time: 13ms
memory: 3956kb
input:
7 1000 891945482
result:
ok accepted: cnt = 7531
Test #78:
score: 60
Accepted
time: 13ms
memory: 3920kb
input:
7 1000 461988571
result:
ok accepted: cnt = 7561
Test #79:
score: 60
Accepted
time: 13ms
memory: 3944kb
input:
7 1000 588921486
result:
ok accepted: cnt = 7545
Test #80:
score: 60
Accepted
time: 13ms
memory: 3920kb
input:
7 1000 819181186
result:
ok accepted: cnt = 7562
Test #81:
score: 60
Accepted
time: 0ms
memory: 4028kb
input:
7 2 509390821
result:
ok accepted: cnt = 2
Test #82:
score: 60
Accepted
time: 0ms
memory: 3784kb
input:
7 3 932973010
result:
ok accepted: cnt = 4
Test #83:
score: 60
Accepted
time: 0ms
memory: 3800kb
input:
7 3 704198002
result:
ok accepted: cnt = 2
Test #84:
score: 60
Accepted
time: 13ms
memory: 4220kb
input:
7 996 844688748
result:
ok accepted: cnt = 7500
Test #85:
score: 60
Accepted
time: 12ms
memory: 4208kb
input:
7 935 983758765
result:
ok accepted: cnt = 7036
Test #86:
score: 60
Accepted
time: 13ms
memory: 4116kb
input:
7 1000 560957955
result:
ok accepted: cnt = 7569
Test #87:
score: 60
Accepted
time: 13ms
memory: 3996kb
input:
7 1000 381616996
result:
ok accepted: cnt = 7632
Test #88:
score: 60
Accepted
time: 10ms
memory: 3944kb
input:
7 1000 607168013
result:
ok accepted: cnt = 7576
Test #89:
score: 60
Accepted
time: 13ms
memory: 3924kb
input:
7 1000 755432541
result:
ok accepted: cnt = 7528
Test #90:
score: 60
Accepted
time: 13ms
memory: 3936kb
input:
7 1000 675700852
result:
ok accepted: cnt = 7601
Test #91:
score: 60
Accepted
time: 0ms
memory: 4032kb
input:
7 2 91873452
result:
ok accepted: cnt = 2
Test #92:
score: 60
Accepted
time: 0ms
memory: 4128kb
input:
7 4 336570576
result:
ok accepted: cnt = 15
Test #93:
score: 60
Accepted
time: 0ms
memory: 4124kb
input:
7 4 617201184
result:
ok accepted: cnt = 23
Test #94:
score: 60
Accepted
time: 11ms
memory: 4124kb
input:
7 904 396880646
result:
ok accepted: cnt = 6731
Test #95:
score: 60
Accepted
time: 7ms
memory: 3864kb
input:
7 906 970970547
result:
ok accepted: cnt = 6801
Test #96:
score: 60
Accepted
time: 13ms
memory: 3924kb
input:
7 1000 960558936
result:
ok accepted: cnt = 7656
Test #97:
score: 60
Accepted
time: 13ms
memory: 3924kb
input:
7 1000 238446836
result:
ok accepted: cnt = 7563
Test #98:
score: 60
Accepted
time: 13ms
memory: 4208kb
input:
7 1000 897094536
result:
ok accepted: cnt = 7666
Test #99:
score: 60
Accepted
time: 13ms
memory: 3936kb
input:
7 1000 820891454
result:
ok accepted: cnt = 7552
Test #100:
score: 60
Accepted
time: 13ms
memory: 4224kb
input:
7 1000 586475353
result:
ok accepted: cnt = 7609