Submission #232796

# Submission time Handle Problem Language Result Execution time Memory
232796 2020-05-18T07:09:00 Z pedy4000 Zagonetka (COI18_zagonetka) C++14
100 / 100
83 ms 508 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

typedef long long ll;

const int N = 1e2 + 2;
int n, k, ans;
int p[N], q[N], ind[N];
int a[N], b[N];
bool adj[N][N];
vector <int> vec;
vector <int> G[N];
set <int> Set;

void dfs (int v) {
	for (int u: G[v])
		if (a[u] == 0)
			dfs(u);
	a[v] = *Set.begin();
	Set.erase(Set.begin());
}

void DFS (int v) {
	for (int u: G[v])
		if (b[u] == 0)
			DFS(u);
	b[v] = *(--Set.end());
	Set.erase(--Set.end());
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		ind[p[i]] = i;
	}
	for (int i = 1; i <= n; i++)
		adj[i][i] = true;

	for (int dif = 1; dif < n; dif++)
		for (int l = 1; l + dif <= n; l++) {
			int r = l + dif;
			bool ok = false;

			for (int k = l + 1; k < r; k++)
				if (adj[l][k] && adj[k][r]) {
					ok = true;
					break;
				}

			if (ok) {
				adj[l][r] = true;
				continue;
			}
			
			for (int k = l; k <= r; k++)
				if (adj[l][k] || adj[k][r])
					vec.push_back(k);
			
			sort(vec.begin(), vec.end());
			for (int i = 0; i < n; i++)
				q[i] = p[i];

			for (int k = r; l <= k; k--)
				if (adj[l][k]) {
					q[ind[k]] = vec.back();
					vec.pop_back();
				}
			for (int k = r; l <= k; k--)
				if (adj[k][r]) {
					q[ind[k]] = vec.back();
					vec.pop_back();
				}

			cout << "query ";
			for (int i = 0; i < n; i++)
				cout << q[i] << " ";
			cout << "\n" << flush;

			cin >> ok;
			adj[l][r] = !ok;
		}

	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			if (adj[i][j])
				G[ind[j]].push_back(ind[i]);
	for (int i = 0; i < n; i++)
		sort(G[i].begin(), G[i].end());

	for (int i = 1; i <= n; i++)
		Set.insert(i);
	
	for (int i = 0; i < n; i++)
		if (a[i] == 0)
			dfs(i);

	for (int i = 0; i < n; i++)
		G[i].clear();

	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			if (adj[i][j])
				G[ind[i]].push_back(ind[j]);
	for (int i = 0; i < n; i++)
		sort(G[i].begin(), G[i].end());

	for (int i = 1; i <= n; i++)
		Set.insert(i);
	
	for (int i = 0; i < n; i++)
		if (b[i] == 0)
			DFS(i);

	cout << "end\n";
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << "\n";
	for (int i = 0; i < n; i++)
		cout << b[i] << " ";
	cout << "\n" << flush;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 396 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 384 KB Output is correct
2 Correct 28 ms 388 KB Output is correct
3 Correct 33 ms 384 KB Output is correct
4 Correct 41 ms 384 KB Output is correct
5 Correct 12 ms 384 KB Output is correct
6 Correct 40 ms 508 KB Output is correct
7 Correct 11 ms 384 KB Output is correct
8 Correct 11 ms 384 KB Output is correct
9 Correct 22 ms 392 KB Output is correct
10 Correct 17 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 9 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 8 ms 396 KB Output is correct
8 Correct 9 ms 384 KB Output is correct
9 Correct 9 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 9 ms 384 KB Output is correct
12 Correct 9 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 384 KB Output is correct
2 Correct 77 ms 504 KB Output is correct
3 Correct 70 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 18 ms 504 KB Output is correct
8 Correct 31 ms 384 KB Output is correct
9 Correct 23 ms 384 KB Output is correct
10 Correct 78 ms 504 KB Output is correct
11 Correct 61 ms 384 KB Output is correct
12 Correct 63 ms 384 KB Output is correct
13 Correct 79 ms 384 KB Output is correct
14 Correct 54 ms 384 KB Output is correct
15 Correct 83 ms 504 KB Output is correct
16 Correct 73 ms 384 KB Output is correct