QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741887#9432. PermutationhappybobRE 1ms3560kbC++201.6kb2024-11-13 15:25:402024-11-13 15:25:47

Judging History

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

  • [2024-11-13 15:25:47]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3560kb
  • [2024-11-13 15:25:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

constexpr int N = 1e3 + 5;

int n;
array<int, N> ans;
mt19937_64 rnd(114514);

inline int query(int l, int x, int y)
{
	cout << "0 ";
	for (int i = 1; i <= l; i++) cout << x << " ";
	for (int i = l + 1; i <= n; i++) cout << y << " ";
	cout << "\n";
	cout.flush();
	int k;
	cin >> k;
	return k;
}

void solve(int l, int r, vector<int> s)
{
	if (l > r) return;
	if (l == r)
	{
		ans[l] = s.front();
		return;
	}
	shuffle(s.begin(), s.end(), rnd);
	int mid = l + r >> 1;
	vector<int> lt, rt, tmp;
	for (int i = 0; i < s.size(); i++)
	{
		if (i < s.size() - 1)
		{
			int x = query(mid, s[i], s[i + 1]);
			if (x == 0)
			{
				lt.emplace_back(s[i + 1]);
				rt.emplace_back(s[i]);
				for (auto &i : tmp) rt.emplace_back(i);
				tmp.clear(), tmp.shrink_to_fit();
			}
			else if (x == 2)
			{
				lt.emplace_back(s[i]);
				rt.emplace_back(s[i + 1]);
				for (auto &i : tmp) lt.emplace_back(i);
				tmp.clear(), tmp.shrink_to_fit();
				i++;
			}
			else
			{
				tmp.emplace_back(s[i]);
			}
		}
		else
		{
			tmp.emplace_back(s[i]);
			if (lt.size() < mid - l + 1)
			{
				for (auto &x : tmp) lt.emplace_back(x);
			}
			else
			{
				for (auto &x : tmp) rt.emplace_back(x);
			}
		}
	}
	solve(l, mid, lt);
	solve(mid + 1, r, rt);
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	vector<int> v;
	for (int i = 1; i <= n; i++) v.emplace_back(i);
	solve(1, n, v);
	cout << "1 ";
	for (int i = 1; i <= n; i++) cout << ans[i] << " ";
	cout << "\n";
	cout.flush();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3560kb

input:

5
2
1
2
1
2
2
2

output:

0 4 4 4 1 1 
0 2 2 2 3 3 
0 3 3 3 5 5 
0 3 3 4 4 4 
0 4 4 2 2 2 
0 3 4 4 4 4 
0 1 1 1 1 5 
1 3 4 2 1 5 

result:

ok Accepted

Test #2:

score: -100
Runtime Error

input:

1000
1
1
1
1
2
1
0
1
2
1
0
1
1
1
2
1
0
1
2
2
0
1
1
2
1
1
1
0
2
1
1
1
2
1
1
0
2
0
2
1
1
1
2
0
1
1
1
2
1
1
0
1
2
1
1
2
0
1
2
1
1
2
0
2
1
0
2
0
1
2
0
2
0
2
1
1
2
0
1
2
0
1
1
1
2
2
2
1
1
2
0
2
0
2
0
2
1
0
1
2
0
1
1
1
1
1
2
0
1
1
2
2
0
1
2
2
1
1
1
1
0
2
2
1
0
1
1
2
1
1
1
1
1
1
2
1
0
1
1
2
2
2
1
1
1
1
1
0...

output:

0 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 562 56...

result: