QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573064#8952. 解谜游戏Kevin5307#0 0ms4132kbC++233.7kb2024-09-18 17:13:472024-09-18 17:13:48

Judging History

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

  • [2024-09-18 17:13:48]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4132kb
  • [2024-09-18 17:13:47]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
#include"puzzle.h"
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
namespace Solver
{
	int cnt=0;
	mt19937_64 rng(20210448);
	int _query(const std::vector<int> &q)
	{
		cnt++;
		assert(cnt<=20000);
		int ans=query(q);
		if(sz(q)==ans)
		{
			check(q);
			exit(0);
		}
		return ans;
	}
	pii get(int n)
	{
		vector<int> vec;
		for(int i=0;i<n;i++)
			vec.pb(i);
		int cnt=_query(vec);
		for(int j=1;j<n;j++)
		{
			vector<int> v2=vec;
			swap(v2[0],v2[j]);
			int cnt2=_query(v2);
			if(cnt==cnt2) continue;
			if(cnt2==cnt+2) return mp(0,v2[0]);
			if(cnt==cnt2+2) return mp(0,vec[0]);
			if(cnt2==cnt+1)
			{
				pii E1=mp(0,v2[0]),E2=mp(j,v2[j]);
				int j2=1;
				while(j2==j) j2++;
				swap(v2[0],v2[j2]);
				cnt2=_query(v2);
				swap(v2[j],v2[j2]);
				if(_query(v2)<cnt2)
					return E2;
				return E1;
			}
			if(cnt==cnt2+1)
			{
				pii E1=mp(0,vec[0]),E2=mp(j,vec[j]);
				int j2=1;
				while(j2==j) j2++;
				swap(vec[0],vec[j2]);
				cnt=_query(vec);
				swap(vec[j],vec[j2]);
				if(_query(vec)<cnt)
					return E2;
				return E1;
			}
		}
		assert(0);
	}
}
void play(int n)
{
	using namespace Solver;
	if(n==1)
		_query({0});
	if(n==2)
	{
		_query({0,1});
		_query({1,0});
	}
	pii pr=get(n);
	assert(n!=5);
	int A=pr.first,B=pr.second;
	vector<int> va,vb;
	for(int i=0;i<n;i++)
		if(i!=A)
			va.pb(i);
	for(int i=0;i<n;i++)
		if(i!=B)
			vb.pb(i);
	vector<int> ans(n);
	ans[A]=B;
	while(sz(va)>1)
	{
		int A1,A2;
		while(true)
		{
			shuffle(ALL(va),rng);
			vector<int> vec1=ans,vec2=ans;
			for(int i=0;i<sz(va)-1;i++)
			{
				vec1[va[i]]=vb[i];
				vec2[va[i]]=vb[i+1];
			}
			vec1[A]=vb.back();
			vec1[va.back()]=B;
			vec2[A]=vb[0];
			vec2[va.back()]=B;
			if((A1=_query(vec1))==(A2=_query(vec2)))
				continue;
			break;
		}
		if(A1<A2)
		{
			int l=0,r=sz(va)-2;
			while(l<r)
			{
				int mid=(l+r)/2;
				vector<int> vec1=ans,vec2=ans;
				for(int i=mid+2;i<sz(va);i++)
					vec1[va[i]]=vec2[va[i]]=vb[i];
				for(int i=0;i<l;i++)
					vec1[va[i]]=vec2[va[i]]=vb[i];
				for(int i=l;i<=mid;i++)
				{
					vec1[va[i]]=vb[i];
					vec2[va[i]]=vb[i+1];
				}
				vec1[va[mid+1]]=vec2[va[mid+1]]=B;
				vec1[A]=vb[mid+1];
				vec2[A]=vb[l];
				if(_query(vec1)<_query(vec2))
					r=mid;
				else
					l=mid+1;
			}
			ans[va[l]]=vb[l+1];
			va.erase(find(ALL(va),va[l]));
			vb.erase(find(ALL(vb),vb[l+1]));
			continue;
		}
		else
		{
			int l=0,r=sz(va)-2;
			while(l<r)
			{
				int mid=(l+r)/2;
				vector<int> vec1=ans,vec2=ans;
				for(int i=mid+2;i<sz(va);i++)
					vec1[va[i]]=vec2[va[i]]=vb[i];
				for(int i=0;i<l;i++)
					vec1[va[i]]=vec2[va[i]]=vb[i];
				for(int i=l;i<=mid;i++)
				{
					vec1[va[i]]=vb[i];
					vec2[va[i]]=vb[i+1];
				}
				vec1[va[mid+1]]=vec2[va[mid+1]]=B;
				vec1[A]=vb[mid+1];
				vec2[A]=vb[l];
				if(_query(vec1)>_query(vec2))
					r=mid;
				else
					l=mid+1;
			}
			ans[va[l]]=vb[l];
			va.erase(find(ALL(va),va[l]));
			vb.erase(find(ALL(vb),vb[l]));
			continue;
		}
	}
	if(sz(va)) ans[va[0]]=vb[0];
	_query(ans);
	check(ans);
	return ;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

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

input:

1 2 816815200

result:

ok accepted: cnt = 2

Test #2:

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

input:

1 3 723182155

result:

ok accepted: cnt = 3

Test #3:

score: 0
Runtime Error

input:

1 5 971867682

result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

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

input:

2 2 931107645

result:

ok accepted: cnt = 2

Test #12:

score: 4
Accepted
time: 0ms
memory: 3828kb

input:

2 4 512124670

result:

ok accepted: cnt = 3

Test #13:

score: 0
Time Limit Exceeded

input:

2 4 793864173

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #21:

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

input:

3 2 667362636

result:

ok accepted: cnt = 1

Test #22:

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

input:

3 4 890842001

result:

ok accepted: cnt = 3

Test #23:

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

input:

3 3 225277415

result:

ok accepted: cnt = 3

Test #24:

score: 0
Time Limit Exceeded

input:

3 26 235413642

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

input:

5 2 527801655

result:

ok accepted: cnt = 2

Test #42:

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

input:

5 5 235665947

result:

ok accepted: cnt = 2

Test #43:

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

input:

5 3 648413779

result:

ok accepted: cnt = 3

Test #44:

score: 0
Time Limit Exceeded

input:

5 272 737778828

result:


Subtask #6:

score: 0
Runtime Error

Test #51:

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

input:

6 2 183795068

result:

ok accepted: cnt = 2

Test #52:

score: 0
Runtime Error

input:

6 5 63668012

result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #61:

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

input:

7 2 412859550

result:

ok accepted: cnt = 2

Test #62:

score: 0
Time Limit Exceeded

input:

7 4 892225546

result: