답안 #1044208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1044208 2024-08-05T08:01:40 Z vjudge1 Zagonetka (COI18_zagonetka) C++17
9 / 100
48 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

int query(vector<int> v)
{
	int x;
	cout<<"query";
	for (int i:v)
		cout<<' '<<i;
	cout<<endl;
	cin>>x;
	return x;
}

signed main()
{
	int n;
	cin>>n;
	int x;
	for (int i=0;i<n;i++)
		cin>>x;
	if (n<=6)
	{
		vector<int> v;
		for (int i=1;i<=n;i++)
			v.push_back(i);
		vector<int> ans,ans1;
		do
		{
			if (query(v))
			{
				if (ans.empty())
					ans=v;
				ans1=v;
			}
		}while(next_permutation(v.begin(),v.end()));
		cout<<"end\n";
		for (int i=0;i<n-1;i++)
			cout<<ans[i]<<' ';
		cout<<ans.back()<<'\n';
		for (int i=0;i<n-1;i++)
			cout<<ans1[i]<<' ';
		cout<<ans1.back()<<endl;
	}
	else
	{
		vector<int> v,ans,ans1;
		for (int i=1;i<=n;i++)
			v.push_back(i);
		x=query(v);
		ans=ans1=v;
		reverse(ans1.begin(),ans1.end());
		if (!x)
		{
			int cnt[n]={},mx=0;
			for (int i=0;i<n;i++)
				for (int j=i+1;j<n;j++)
				{
					swap(v[i],v[j]);
					if (query(v))
						cnt[i]++,cnt[j]++,mx=max(mx,max(cnt[i],cnt[j]));
					swap(v[i],v[j]);
				}
			int pi=-1,pj=0;
			for (int i=0;i<n;i++)
				if (cnt[i]==mx)
				{
					if (pi==-1)
						pi=i;
					else
						pj=i;
				}
			for (int i=pi+1;i<=pj;i++)
				swap(ans[i],ans[i-1]);
		}
		else
		{
			v=ans1;
			int cnt[n]={},mx=0;
			for (int i=0;i<n;i++)
				for (int j=i+1;j<n;j++)
				{
					swap(v[i],v[j]);
					if (query(v))
						cnt[i]++,cnt[j]++,mx=max(mx,max(cnt[i],cnt[j]));
					swap(v[i],v[j]);
				}
			int pi=-1,pj=0;
			for (int i=0;i<n;i++)
				if (cnt[i]==mx)
				{
					if (pi==-1)
						pi=i;
					else
						pj=i;
				}
			for (int i=pi+1;i<=pj;i++)
				swap(ans1[i],ans1[i-1]);
		}
		cout<<"end\n";
		for (int i=0;i<n-1;i++)
			cout<<ans[i]<<' ';
		cout<<ans.back()<<'\n';
		for (int i=0;i<n-1;i++)
			cout<<ans1[i]<<' ';
		cout<<ans1.back()<<endl;
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -