QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#831158#8952. 解谜游戏275307894a#0 1ms4000kbC++142.6kb2024-12-25 11:17:142024-12-25 11:17:24

Judging History

你现在查看的是最新测评结果

  • [2024-12-25 11:17:24]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:4000kb
  • [2024-12-25 11:17:14]
  • 提交

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);
}
void play(int nn){
	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);
	}
	int cnt=0;
	for(int i=1;i<n;i++){
		swap(p[0],p[i]);
		int w=query(p);
		if(w){
			vis[i]=1;
			if(w==2) vis[0]=1;
			cnt=w;
			break;
		}
		swap(p[0],p[i]);
	}
	for(int i=0;i<n;i++) if(vis[i]) rgt.push_back(i);
	while(cnt^n){
		int w=cnt;
		gdb(w,p[0],p[1],p[2],p[3],p[4],rgt[0]);
		while(w==cnt){
			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;
				while(ap[x]) x=R(n)-1;
				p[i]=x;ap[x]=1;
			}
			w=query(p);
			// gdb(w,p[0],p[1],p[2],p[3],p[4]);
		}
		vector<int> st;
		for(int i=0;i<=n;i++){
			if(i<n&&!vis[i]) st.push_back(i);
			if(i==n||st.size()==cnt){
				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: 0
Time Limit Exceeded

Test #1:

score: 2
Accepted
time: 0ms
memory: 3840kb

input:

1 2 816815200

result:

ok accepted: cnt = 3

Test #2:

score: 0
Time Limit Exceeded

input:

1 3 723182155

result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 4
Accepted
time: 1ms
memory: 4000kb

input:

2 2 931107645

result:

ok accepted: cnt = 3

Test #12:

score: 0
Time Limit Exceeded

input:

2 4 512124670

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #21:

score: 6
Accepted
time: 0ms
memory: 3880kb

input:

3 2 667362636

result:

ok accepted: cnt = 2

Test #22:

score: 0
Time Limit Exceeded

input:

3 4 890842001

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #36:

score: 0
Time Limit Exceeded

input:

4 100 6610818

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #41:

score: 10
Accepted
time: 0ms
memory: 4000kb

input:

5 2 527801655

result:

ok accepted: cnt = 3

Test #42:

score: 0
Time Limit Exceeded

input:

5 5 235665947

result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #51:

score: 10
Accepted
time: 1ms
memory: 3884kb

input:

6 2 183795068

result:

ok accepted: cnt = 3

Test #52:

score: 0
Time Limit Exceeded

input:

6 5 63668012

result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #61:

score: 60
Accepted
time: 0ms
memory: 3812kb

input:

7 2 412859550

result:

ok accepted: cnt = 3

Test #62:

score: 0
Time Limit Exceeded

input:

7 4 892225546

result: