QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#831184#8952. 解谜游戏275307894a#Compile Error//C++143.5kb2024-12-25 11:34:592024-12-25 11:35:00

Judging History

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

  • [2024-12-25 11:35:00]
  • 评测
  • [2024-12-25 11:34:59]
  • 提交

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;
int query(vector<int> q){
	int cnt=0;qcnt++;
	for(int i=0;i<nn;i++) cnt+=(q[i]==pp[i]);
	return cnt;
}
void check(vector<int> q){
	for(int i=0;i<nn;i++) if(pp[i]^q[i]){puts("-1");return;}
	printf("Step is %d",qcnt);
	return;
}
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){
	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);
	}
	int cnt=0;
	for(int i=1;i<n;i++){
		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]);
	}
	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],vis[2]);
		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]);
		}
		// gdb(w,p[0],p[1],p[2]);
		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);
}
int main(){
	mt19937 rnd(time(0));
	/*while(1){
		qcnt=0;vis.clear();p.clear();rgt.clear();
		nn=R(5);
		gdb(nn);
		iota(pp,pp+nn,0);
		shuffle(pp,pp+nn,rnd);
		for(int i=0;i<nn;i++) gdb(pp[i]);
		// for(int i=0;i<nn;i++) scanf("%d",&pp[i]);
		play(nn);
	}*/
	scanf("%d",&nn);
	for(int i=0;i<nn;i++) scanf("%d",&pp[i]);
	play(nn);
	
}

详细

implementer.cpp: In constructor ‘a068d5f76423877cf1d63d2b66a308e7::Puzzle::Puzzle()’:
implementer.cpp:45:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                         scanf("%d%d%d",&id,&n,&seed);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
answer.code: In function ‘void divide(std::vector<int>, int, int)’:
answer.code:50:23: error: call of overloaded ‘query(std::vector<int>&)’ is ambiguous
   50 |         int pw=w-query(p)-s1.size();
      |                  ~~~~~^~~
In file included from answer.code:2:
puzzle.h:5:5: note: candidate: ‘int query(const std::vector<int>&)’
    5 | int query(const std::vector<int>&);
      |     ^~~~~
answer.code:29:5: note: candidate: ‘int query(std::vector<int>)’
   29 | int query(vector<int> q){
      |     ^~~~~
answer.code: In function ‘void play(int)’:
answer.code:59:30: error: call of overloaded ‘check(std::vector<int>&)’ is ambiguous
   59 |         if(n==1) return check(p);
      |                         ~~~~~^~~
puzzle.h:6:6: note: candidate: ‘void check(const std::vector<int>&)’
    6 | void check(const std::vector<int>&);
      |      ^~~~~
answer.code:34:6: note: candidate: ‘void check(std::vector<int>)’
   34 | void check(vector<int> q){
      |      ^~~~~
answer.code:61:20: error: call of overloaded ‘query(std::vector<int>&)’ is ambiguous
   61 |         while(query(p)){
      |               ~~~~~^~~
puzzle.h:5:5: note: candidate: ‘int query(const std::vector<int>&)’
    5 | int query(const std::vector<int>&);
      |     ^~~~~
answer.code:29:5: note: candidate: ‘int query(std::vector<int>)’
   29 | int query(vector<int> q){
      |     ^~~~~
answer.code:67:28: error: call of overloaded ‘query(std::vector<int>&)’ is ambiguous
   67 |                 int w=query(p);
      |                       ~~~~~^~~
puzzle.h:5:5: note: candidate: ‘int query(const std::vector<int>&)’
    5 | int query(const std::vector<int>&);
      |     ^~~~~
answer.code:29:5: note: candidate: ‘int query(std::vector<int>)’
   29 | int query(vector<int> q){
      |     ^~~~~
answer.code:77:42: error: call of overloaded ‘query(std::vector<int>&)’ is ambiguous
   77 |                                 if(!query(q)){vis[i]=1;break;}
      |                                     ~~~~~^~~
puzzle.h:5:5: note: candidate: ‘int query(const std::vector<int>&)’
    5 | int query(const std::vector<int>&);
      |     ^~~~~
answer.code:29:5: note: candidate: ‘int query(std::vector<int>)’
   29 | int query(vector<int> q){
      |     ^~~~~
answer.code:82:42: error: call of overloaded ‘query(std::vector<int>&)’ is ambiguous
   82 |                                 if(!query(q)){vis[0]=1;break;}
      |                                     ~~~~~^~~
puzzle.h:5:5: note: candidate: ‘int query(const std::vector<int>&)’
    5 | int query(const std::vector<int>&);
      |     ^~~~~
answer.code:29:5: note: candidate: ‘int query(std::vector<int>)’
   29 | int query(vector<int> q){
      |     ^~~~~
answer.code:101:32: error: call of overloaded ‘query(std::vector<int>&)’ is ambiguous
  101 |                         w=query(p);
      |                           ~~~~~^~~
puzzle.h:5:5: note: candidate: ‘int query(const std::vector<int>&)’
    5 | int query(const std::vector<int>&);
      |     ^~~~~
answer.code:29:5: note: candidate: ‘int query(std::vector<int>)’
   29 | int query(vector<int> q){
      |     ^~~~~
answer.code:110:45: error: call of overloaded ‘query(std::vector<int>&)’ is ambiguous
  110 |                                 int pw=query(p);
      |                                        ~~~~~^~~
puzzle.h:5:5: note: candidate: ‘int query(const std::vector<int>&)’
    5 | int query(const std::vector<int>&);
      |     ^~~~~
answer.code:29:5: note: candidate: ‘int query(std::vector<int>)’
   29 | int query(vector<int> q){
      |     ^~~~~
answer.code:120:14: error: call of overloaded ‘check(std::vector<int>&)’ is ambiguous
  120 |         check(p);
      |         ~~~~~^~~
puzzle.h:6:6: note: candidate: ‘void check(const std::vector<int>&)’
    6 | void check(const std::vector<int>&);
      |      ^~~~~
answer.code:34:6: note: candidate: ‘void check(std::vector<int>)’
   34 | void check(vector<int> q){
      |      ^~~~~
answer.code: In function ‘int main()’:
answer.code:134:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  134 |         scanf("%d",&nn);
      |         ~~~~~^~~~~~~~~~
answer.code:135:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  135 |         for(int i=0;i<nn;i++) scanf("%d",&pp[i]);
      |                               ~~~~~^~~~~~~~~~~~~