답안 #232789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232789 2020-05-18T06:17:47 Z pedy4000 Zagonetka (COI18_zagonetka) C++14
9 / 100
68 ms 504 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];
int d[N];
set <int> Set;

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 < 100; 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]) {
				d[ind[j]]++;
				G[ind[i]].push_back(ind[j]);
			}

	for (int i = 0; i < n; i++)
		if (d[i] == 0)
			Set.insert(i);
	
	for (int i = 1; i <= n; i++) {
		int v = *Set.begin();
		Set.erase(Set.begin());

		a[v] = i;
		for (int u: G[v]) {
			d[u]--;
			if (!d[u])
				Set.insert(u);
		}
	}

	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			if (adj[i][j])
				d[ind[j]]++;

	for (int i = 0; i < n; i++)
		if (d[i] == 0)
			Set.insert(i);
	
	for (int i = 1; i <= n; i++) {
		int v = *(--Set.end());
		Set.erase(--Set.end());

		b[v] = i;
		for (int u: G[v]) {
			d[u]--;
			if (!d[u])
				Set.insert(u);
		}
	}

	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 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 384 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
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 392 KB Output is correct
2 Incorrect 28 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -