QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831511 | #8952. 解谜游戏 | 275307894a | 86.18 | 173ms | 8104kb | C++14 | 3.5kb | 2024-12-25 15:13:17 | 2024-12-25 15:13:22 |
Judging History
answer
#include<bits/stdc++.h>
#include "puzzle.h"
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e3+5,M=(1<<28)+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int nn,pp[N],qcnt;
vector<int> p,vis,rgt;
int n;
void divide(vector<int> st,int sum,int w){
if(!sum) return;
if(st.size()==1){
vis[st[0]]=1;rgt.push_back(st[0]);
return;
}
int m=st.size()/2;
vector<int> s1(st.begin(),st.begin()+m),s2(st.begin()+m,st.end());
for(int i=0;i<s1.size();i++) swap(p[s1[i]],p[rgt[i]]);
int pw=w-query(p)-s1.size();
// gdb(pw);
for(int i=0;i<s1.size();i++) swap(p[s1[i]],p[rgt[i]]);
divide(s1,pw,w);divide(s2,sum-pw,w);
}
int alp[N][N];
void play(int nn){
mt19937 rnd(28382);
n=nn;p.resize(n);vis.resize(n);
iota(all(p),0);
if(n==1) return check(p);
shuffle(all(p),rnd);
while(query(p)){
shuffle(all(p),rnd);
}
for(int i=0;i<n;i++) alp[p[i]][i]=1;
int cnt=0;
vector<int> id(n-1);
iota(all(id),1);shuffle(all(id),rnd);
for(int i:id){
swap(p[0],p[i]);
int w=query(p);
if(w){
if(w==2){
cnt=w;vis[i]=vis[0]=1;
break;
}
int w1=p[0],w2=p[i];
while(1){
auto q=p;
shuffle(q.begin()+1,q.end(),rnd);
if(!query(q)){vis[i]=1;break;}
q=p;
swap(q[0],q[i]);
shuffle(q.begin()+1,q.end(),rnd);
swap(q[0],q[i]);
if(!query(q)){vis[0]=1;break;}
}
cnt=1;break;
break;
}
swap(p[0],p[i]);
}
gdb(qcnt);
for(int i=0;i<n;i++) if(vis[i]) rgt.push_back(i);
int cts=0;
while(cnt^n){
int w=cnt;
// gdb(w,p[0],p[1],p[2],p[3],p[4],rgt[0],vis[2]);
while(w==cnt){
for(int i=0;i<n;i++) if(!vis[i]) alp[p[i]][i]=1;
static int ap[N];Me(ap,0);
for(int i:rgt) ap[p[i]]=1;
for(int i=0;i<n;i++) if(!vis[i]){
int x=R(n)-1;
int k=100;
while(ap[x]||(k&&alp[x][i])){
if(!ap[x]&&alp[x][i]) k--;
x=R(n)-1;
}
p[i]=x;ap[x]=1;
}
int flag=0;
for(int i=0;i<n;i++) if(!vis[i]&&!alp[p[i]][i]) flag=1;
if(!flag) continue;
w=query(p);
cts++;
// gdb(w,p[0],p[1],p[2],p[3],p[4]);
}
// gdb(w,p[0],p[1],p[2]);
vector<int> st;
vector<int> id(n+1);
iota(all(id),0);shuffle(id.begin(),id.begin()+n,rnd);
for(int i:id)if(rgt.size()<w){
if(i<n&&!vis[i]&&!alp[p[i]][i]) st.push_back(i);
if(i==n||st.size()==rgt.size()){
if(i==n){
divide(st,w-rgt.size(),w);
}else{
for(int i=0;i<st.size();i++) swap(p[st[i]],p[rgt[i]]);
int pw=query(p);
for(int i=0;i<st.size();i++) swap(p[st[i]],p[rgt[i]]);
if(pw<w-st.size()){
divide(st,w-pw-st.size(),w);
}
}
st.clear();
}
}
cnt=w;
}
check(p);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 0ms
memory: 3808kb
input:
1 2 816815200
result:
ok accepted: cnt = 2
Test #2:
score: 2
Accepted
time: 0ms
memory: 3868kb
input:
1 3 723182155
result:
ok accepted: cnt = 21
Test #3:
score: 2
Accepted
time: 0ms
memory: 4124kb
input:
1 5 971867682
result:
ok accepted: cnt = 7
Test #4:
score: 2
Accepted
time: 0ms
memory: 3860kb
input:
1 3 887042235
result:
ok accepted: cnt = 6
Test #5:
score: 2
Accepted
time: 0ms
memory: 3828kb
input:
1 3 568659743
result:
ok accepted: cnt = 21
Test #6:
score: 2
Accepted
time: 0ms
memory: 3832kb
input:
1 5 930991667
result:
ok accepted: cnt = 17
Test #7:
score: 2
Accepted
time: 0ms
memory: 4032kb
input:
1 5 185481439
result:
ok accepted: cnt = 11
Test #8:
score: 2
Accepted
time: 0ms
memory: 3844kb
input:
1 5 405685705
result:
ok accepted: cnt = 9
Test #9:
score: 2
Accepted
time: 0ms
memory: 3844kb
input:
1 5 693401039
result:
ok accepted: cnt = 12
Test #10:
score: 2
Accepted
time: 0ms
memory: 3836kb
input:
1 5 570594473
result:
ok accepted: cnt = 13
Subtask #2:
score: 4
Accepted
Test #11:
score: 4
Accepted
time: 0ms
memory: 4100kb
input:
2 2 931107645
result:
ok accepted: cnt = 2
Test #12:
score: 4
Accepted
time: 0ms
memory: 3892kb
input:
2 4 512124670
result:
ok accepted: cnt = 10
Test #13:
score: 4
Accepted
time: 0ms
memory: 4120kb
input:
2 4 793864173
result:
ok accepted: cnt = 15
Test #14:
score: 4
Accepted
time: 0ms
memory: 3800kb
input:
2 7 322910591
result:
ok accepted: cnt = 14
Test #15:
score: 4
Accepted
time: 0ms
memory: 3796kb
input:
2 9 316192686
result:
ok accepted: cnt = 26
Test #16:
score: 4
Accepted
time: 0ms
memory: 3888kb
input:
2 10 350886420
result:
ok accepted: cnt = 22
Test #17:
score: 4
Accepted
time: 0ms
memory: 3860kb
input:
2 10 914937911
result:
ok accepted: cnt = 39
Test #18:
score: 4
Accepted
time: 0ms
memory: 4152kb
input:
2 10 68729974
result:
ok accepted: cnt = 28
Test #19:
score: 4
Accepted
time: 0ms
memory: 4048kb
input:
2 10 15788440
result:
ok accepted: cnt = 30
Test #20:
score: 4
Accepted
time: 0ms
memory: 3840kb
input:
2 10 950846282
result:
ok accepted: cnt = 24
Subtask #3:
score: 6
Accepted
Test #21:
score: 6
Accepted
time: 0ms
memory: 3852kb
input:
3 2 667362636
result:
ok accepted: cnt = 4
Test #22:
score: 6
Accepted
time: 0ms
memory: 3776kb
input:
3 4 890842001
result:
ok accepted: cnt = 10
Test #23:
score: 6
Accepted
time: 0ms
memory: 4024kb
input:
3 3 225277415
result:
ok accepted: cnt = 10
Test #24:
score: 6
Accepted
time: 0ms
memory: 4112kb
input:
3 26 235413642
result:
ok accepted: cnt = 92
Test #25:
score: 6
Accepted
time: 1ms
memory: 3860kb
input:
3 25 139642984
result:
ok accepted: cnt = 113
Test #26:
score: 6
Accepted
time: 0ms
memory: 3884kb
input:
3 30 991911708
result:
ok accepted: cnt = 115
Test #27:
score: 6
Accepted
time: 0ms
memory: 3936kb
input:
3 30 4514256
result:
ok accepted: cnt = 120
Test #28:
score: 6
Accepted
time: 1ms
memory: 3876kb
input:
3 30 157113423
result:
ok accepted: cnt = 122
Test #29:
score: 6
Accepted
time: 0ms
memory: 4008kb
input:
3 30 557648974
result:
ok accepted: cnt = 111
Test #30:
score: 6
Accepted
time: 1ms
memory: 3944kb
input:
3 30 645022468
result:
ok accepted: cnt = 144
Test #31:
score: 6
Accepted
time: 0ms
memory: 4104kb
input:
4 2 427653480
result:
ok accepted: cnt = 4
Test #32:
score: 6
Accepted
time: 0ms
memory: 3836kb
input:
4 3 219860551
result:
ok accepted: cnt = 21
Test #33:
score: 6
Accepted
time: 0ms
memory: 3828kb
input:
4 4 165138325
result:
ok accepted: cnt = 8
Test #34:
score: 6
Accepted
time: 2ms
memory: 4380kb
input:
4 93 525060479
result:
ok accepted: cnt = 527
Test #35:
score: 6
Accepted
time: 2ms
memory: 6084kb
input:
4 99 829735778
result:
ok accepted: cnt = 593
Subtask #4:
score: 8
Accepted
Test #36:
score: 8
Accepted
time: 2ms
memory: 4180kb
input:
4 100 6610818
result:
ok accepted: cnt = 525
Test #37:
score: 8
Accepted
time: 2ms
memory: 4248kb
input:
4 100 653323659
result:
ok accepted: cnt = 662
Test #38:
score: 8
Accepted
time: 2ms
memory: 4504kb
input:
4 100 268513130
result:
ok accepted: cnt = 613
Test #39:
score: 8
Accepted
time: 2ms
memory: 4220kb
input:
4 100 479581529
result:
ok accepted: cnt = 582
Test #40:
score: 8
Accepted
time: 2ms
memory: 4220kb
input:
4 100 119844914
result:
ok accepted: cnt = 574
Subtask #5:
score: 10
Accepted
Test #41:
score: 10
Accepted
time: 0ms
memory: 4008kb
input:
5 2 527801655
result:
ok accepted: cnt = 2
Test #42:
score: 10
Accepted
time: 0ms
memory: 3836kb
input:
5 5 235665947
result:
ok accepted: cnt = 12
Test #43:
score: 10
Accepted
time: 0ms
memory: 3800kb
input:
5 3 648413779
result:
ok accepted: cnt = 10
Test #44:
score: 10
Accepted
time: 13ms
memory: 6820kb
input:
5 272 737778828
result:
ok accepted: cnt = 2151
Test #45:
score: 10
Accepted
time: 7ms
memory: 6036kb
input:
5 278 173436130
result:
ok accepted: cnt = 1899
Test #46:
score: 10
Accepted
time: 13ms
memory: 5024kb
input:
5 300 997862299
result:
ok accepted: cnt = 2371
Test #47:
score: 10
Accepted
time: 13ms
memory: 5060kb
input:
5 300 764271855
result:
ok accepted: cnt = 2031
Test #48:
score: 10
Accepted
time: 14ms
memory: 6572kb
input:
5 300 428892383
result:
ok accepted: cnt = 2114
Test #49:
score: 10
Accepted
time: 15ms
memory: 6632kb
input:
5 300 166706392
result:
ok accepted: cnt = 2177
Test #50:
score: 10
Accepted
time: 9ms
memory: 6664kb
input:
5 300 843444435
result:
ok accepted: cnt = 2043
Subtask #6:
score: 10
Accepted
Test #51:
score: 10
Accepted
time: 0ms
memory: 4108kb
input:
6 2 183795068
result:
ok accepted: cnt = 2
Test #52:
score: 10
Accepted
time: 0ms
memory: 3808kb
input:
6 5 63668012
result:
ok accepted: cnt = 13
Test #53:
score: 10
Accepted
time: 0ms
memory: 4132kb
input:
6 5 990398365
result:
ok accepted: cnt = 11
Test #54:
score: 10
Accepted
time: 34ms
memory: 6876kb
input:
6 488 942578687
result:
ok accepted: cnt = 4103
Test #55:
score: 10
Accepted
time: 28ms
memory: 5732kb
input:
6 475 915148470
result:
ok accepted: cnt = 3844
Test #56:
score: 10
Accepted
time: 35ms
memory: 5840kb
input:
6 500 736505651
result:
ok accepted: cnt = 3939
Test #57:
score: 10
Accepted
time: 33ms
memory: 7432kb
input:
6 500 352417213
result:
ok accepted: cnt = 3582
Test #58:
score: 10
Accepted
time: 36ms
memory: 6216kb
input:
6 500 80534667
result:
ok accepted: cnt = 4006
Test #59:
score: 10
Accepted
time: 33ms
memory: 7472kb
input:
6 500 811975157
result:
ok accepted: cnt = 3907
Test #60:
score: 10
Accepted
time: 38ms
memory: 7292kb
input:
6 500 471392863
result:
ok accepted: cnt = 3647
Subtask #7:
score: 46.18
Acceptable Answer
Test #61:
score: 60
Accepted
time: 0ms
memory: 3816kb
input:
7 2 412859550
result:
ok accepted: cnt = 2
Test #62:
score: 60
Accepted
time: 0ms
memory: 4116kb
input:
7 4 892225546
result:
ok accepted: cnt = 8
Test #63:
score: 60
Accepted
time: 0ms
memory: 3896kb
input:
7 4 577686541
result:
ok accepted: cnt = 12
Test #64:
score: 60
Accepted
time: 121ms
memory: 7888kb
input:
7 902 974849567
result:
ok accepted: cnt = 8065
Test #65:
score: 60
Accepted
time: 136ms
memory: 7648kb
input:
7 939 155203710
result:
ok accepted: cnt = 8273
Test #66:
score: 49.6467
Acceptable Answer
time: 164ms
memory: 7920kb
input:
7 1000 253107507
result:
points 0.8274444444 partially_correct: cnt = 9606
Test #67:
score: 48.7533
Acceptable Answer
time: 164ms
memory: 7900kb
input:
7 1000 882029420
result:
points 0.8125555556 partially_correct: cnt = 9874
Test #68:
score: 60
Accepted
time: 158ms
memory: 7888kb
input:
7 1000 199421982
result:
ok accepted: cnt = 9360
Test #69:
score: 49.01
Acceptable Answer
time: 147ms
memory: 7828kb
input:
7 1000 749220884
result:
points 0.8168333333 partially_correct: cnt = 9797
Test #70:
score: 60
Accepted
time: 148ms
memory: 7952kb
input:
7 1000 729055050
result:
ok accepted: cnt = 9197
Test #71:
score: 60
Accepted
time: 0ms
memory: 3756kb
input:
7 2 375338281
result:
ok accepted: cnt = 4
Test #72:
score: 60
Accepted
time: 0ms
memory: 3844kb
input:
7 5 914443594
result:
ok accepted: cnt = 18
Test #73:
score: 60
Accepted
time: 0ms
memory: 3840kb
input:
7 5 310479620
result:
ok accepted: cnt = 14
Test #74:
score: 60
Accepted
time: 167ms
memory: 7816kb
input:
7 982 660842623
result:
ok accepted: cnt = 8536
Test #75:
score: 49.6133
Acceptable Answer
time: 147ms
memory: 8104kb
input:
7 985 92435101
result:
points 0.8268888889 partially_correct: cnt = 9616
Test #76:
score: 60
Accepted
time: 160ms
memory: 7860kb
input:
7 1000 901527471
result:
ok accepted: cnt = 9494
Test #77:
score: 49.7
Acceptable Answer
time: 155ms
memory: 7840kb
input:
7 1000 891945482
result:
points 0.8283333333 partially_correct: cnt = 9590
Test #78:
score: 60
Accepted
time: 159ms
memory: 7952kb
input:
7 1000 461988571
result:
ok accepted: cnt = 9487
Test #79:
score: 60
Accepted
time: 153ms
memory: 7888kb
input:
7 1000 588921486
result:
ok accepted: cnt = 9443
Test #80:
score: 60
Accepted
time: 166ms
memory: 7968kb
input:
7 1000 819181186
result:
ok accepted: cnt = 9094
Test #81:
score: 60
Accepted
time: 0ms
memory: 3896kb
input:
7 2 509390821
result:
ok accepted: cnt = 2
Test #82:
score: 60
Accepted
time: 0ms
memory: 3772kb
input:
7 3 932973010
result:
ok accepted: cnt = 7
Test #83:
score: 60
Accepted
time: 0ms
memory: 4120kb
input:
7 3 704198002
result:
ok accepted: cnt = 5
Test #84:
score: 60
Accepted
time: 160ms
memory: 7812kb
input:
7 996 844688748
result:
ok accepted: cnt = 9433
Test #85:
score: 60
Accepted
time: 133ms
memory: 7824kb
input:
7 935 983758765
result:
ok accepted: cnt = 8291
Test #86:
score: 60
Accepted
time: 155ms
memory: 7892kb
input:
7 1000 560957955
result:
ok accepted: cnt = 9168
Test #87:
score: 60
Accepted
time: 173ms
memory: 7900kb
input:
7 1000 381616996
result:
ok accepted: cnt = 8928
Test #88:
score: 49.78
Acceptable Answer
time: 154ms
memory: 7884kb
input:
7 1000 607168013
result:
points 0.8296666667 partially_correct: cnt = 9566
Test #89:
score: 48.8133
Acceptable Answer
time: 159ms
memory: 7924kb
input:
7 1000 755432541
result:
points 0.8135555556 partially_correct: cnt = 9856
Test #90:
score: 49.7167
Acceptable Answer
time: 152ms
memory: 7940kb
input:
7 1000 675700852
result:
points 0.8286111111 partially_correct: cnt = 9585
Test #91:
score: 60
Accepted
time: 0ms
memory: 4104kb
input:
7 2 91873452
result:
ok accepted: cnt = 2
Test #92:
score: 60
Accepted
time: 0ms
memory: 3828kb
input:
7 4 336570576
result:
ok accepted: cnt = 16
Test #93:
score: 60
Accepted
time: 0ms
memory: 4120kb
input:
7 4 617201184
result:
ok accepted: cnt = 7
Test #94:
score: 60
Accepted
time: 121ms
memory: 7536kb
input:
7 904 396880646
result:
ok accepted: cnt = 8266
Test #95:
score: 60
Accepted
time: 131ms
memory: 7532kb
input:
7 906 970970547
result:
ok accepted: cnt = 8558
Test #96:
score: 60
Accepted
time: 144ms
memory: 7880kb
input:
7 1000 960558936
result:
ok accepted: cnt = 9271
Test #97:
score: 48.5467
Acceptable Answer
time: 156ms
memory: 7884kb
input:
7 1000 238446836
result:
points 0.8091111111 partially_correct: cnt = 9936
Test #98:
score: 48.6167
Acceptable Answer
time: 158ms
memory: 7856kb
input:
7 1000 897094536
result:
points 0.8102777778 partially_correct: cnt = 9915
Test #99:
score: 46.18
Acceptable Answer
time: 154ms
memory: 7924kb
input:
7 1000 820891454
result:
points 0.7696666667 partially_correct: cnt = 10646
Test #100:
score: 48.4533
Acceptable Answer
time: 157ms
memory: 7856kb
input:
7 1000 586475353
result:
points 0.8075555556 partially_correct: cnt = 9964