QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560998#8952. 解谜游戏zhouhuanyi0 0ms4072kbC++232.4kb2024-09-12 19:24:042024-09-12 19:24:05

Judging History

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

  • [2024-09-12 19:24:05]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4072kb
  • [2024-09-12 19:24:04]
  • 提交

answer

#include "puzzle.h"
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<random>
#define N 1000
using namespace std;
mt19937 RAND(random_device{}());
struct reads
{
	int x,y;
};
vector<reads>p[N+1];
int tn,n,length,tong[N+1],rd[N+1];
bool used[N+1];
vector<int>E[N+1];
int get(int x)
{
	if (x>tn) x-=tn;
	if (x<1) x+=tn;
	return x;
}
void add_edge(int x,int y)
{
	E[x].push_back(y),E[y].push_back(x);
	return;
}
void solve(vector<reads>sp,int res)
{
	if (!res) return;
	if (sp.size()==1)
	{
		for (int i=0;i<sp.size();++i) add_edge(sp[i].x,sp[i].y);
		return;
	}
	vector<reads>A;
	vector<reads>B;
	int mid=sp.size()>>1,d;
	vector<int>tp(n);
	for (int i=1;i<=n;++i) tp[i-1]=rd[i];
	for (int i=0;i<mid;++i) A.push_back(sp[i]),tp[sp[i].x-1]=rd[sp[i].y],tp[sp[i].y-1]=rd[sp[i].x];
	for (int i=mid;i<sp.size();++i) B.push_back(sp[i]);
	d=query(tp),solve(A,d),solve(B,res-d);
	return;
}
void dfs(int x)
{
	used[x]=1,tong[++length]=x;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			dfs(E[x][i]);
	return;
}
void play(int sn)
{
	n=sn;
	vector<reads>tp;
	vector<int>sp(n);
	vector<int>ans(n);
	for (int i=0;i<n;++i) sp[i]=i;
	while (1)
	{
		shuffle(sp.begin(),sp.end(),RAND);
		if (!query(sp)) break;
	}
	for (int i=1;i<=n;++i) rd[i]=sp[i-1];
	if (!(n&1))
	{
		tn=n-1;
		for (int i=1;i<=n-1;++i)
		{
			p[i].push_back((reads){i,n});
			for (int j=1;j<=(n>>1)-1;++j) p[i].push_back((reads){get(i-j),get(i+j)});
		}
	}
	else
	{
		tn=n;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=(n>>1);++j)
				p[i].push_back((reads){get(i-j),get(i+j)});
	}
	for (int i=1;i<=n;++i)
		if (!p[i].empty())
		{
			tp.clear();
			for (int j=0;j<p[i].size();++j)
				if (E[p[i][j].x].size()<=1&&E[p[i][j].y].size()<=1)
					tp.push_back(p[i][j]);
			if (!tp.empty())
			{
				for (int j=1;j<=n;++j) sp[j-1]=rd[j];
				for (int j=0;j<tp.size();++j) sp[tp[j].x-1]=rd[tp[j].y],sp[tp[j].y-1]=rd[tp[j].x];
				solve(tp,query(sp));
			}
		}
	for (int i=1;i<=n;++i)
		if (!used[i])
		{
			length=0,dfs(i);
			for (int j=1;j<=n;++j) sp[j-1]=rd[j];
			for (int j=1;j<=length;++j) sp[tong[j]-1]=rd[tong[j%length+1]];
			if (query(sp))
			{
				for (int j=1;j<=length;++j) ans[tong[j]-1]=rd[tong[j%length+1]];
			}
			else
			{
				for (int j=1;j<=length;++j) ans[tong[j%length+1]-1]=rd[tong[j]];
			}
		}
	check(ans);
	return;
}

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: 3828kb

input:

1 2 816815200

result:

ok accepted: cnt = 4

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: 0ms
memory: 4072kb

input:

2 2 931107645

result:

ok accepted: cnt = 4

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: 3792kb

input:

3 2 667362636

result:

ok accepted: cnt = 3

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: 3728kb

input:

5 2 527801655

result:

ok accepted: cnt = 4

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: 0ms
memory: 4068kb

input:

6 2 183795068

result:

ok accepted: cnt = 4

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: 3680kb

input:

7 2 412859550

result:

ok accepted: cnt = 4

Test #62:

score: 0
Time Limit Exceeded

input:

7 4 892225546

result: