Submission #70793

# Submission time Handle Problem Language Result Execution time Memory
70793 2018-08-23T11:29:55 Z Bruteforceman Zagonetka (COI18_zagonetka) C++11
100 / 100
165 ms 976 KB
#include "bits/stdc++.h"
using namespace std;
int n;
vector <int> p;
typedef pair <int, int> pii;

bool query(vector <int> v) {
	vector <int> p (v.size());
	for(size_t i = 0; i < v.size(); i++) {
		p[v[i]] = i;
	}
	cout << "query";
	for(auto i : p) {
		cout << " " << (i+1);
	}
	cout << endl;
	int ans;
	cin >> ans;
	return ans;
}

vector <int> g[111];
bool vis[111];

void dfs(int x) {
	vis[x] = true;
	for(auto i : g[x]) {
		if(!vis[i]) {
			dfs(i);
		}
	}
} 

vector <int> A;
bool del[111];
bool visit[111];
set <int> reach[111];

void travel(int x) {
	if(visit[x]) return ;
	visit[x] = true;
	reach[x].insert(x);
	for(auto i : g[x]) {
		travel(i);
		for(auto j : reach[i]) {
			reach[x].insert(j);
		}
	}
}
void solve(int x) {
	del[x] = true;
	for(auto i : reach[x]) {
		if(del[i]) continue;
		solve(i);
	}
	A.push_back(x);
}

vector <int> order(vector <pii> e) {
	for(int i = 0; i < n; i++) {
		g[i].clear();
		reach[i].clear();
	}
	for(int i = 0; i < e.size(); i++) {
		g[e[i].second].push_back(e[i].first);
	}
	memset(visit, false, sizeof visit);
	memset(del, false, sizeof del);
	for(int i = 0; i < n; i++) {
		travel(i);
	}
	A.clear();
	for(int i = 0; i < n; i++) {
		if(!del[i]) solve(i);
	}
	return A;
}

int main(int argc, char const *argv[])
{
	cin >> n;
	p.resize(n);
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		p[x-1] = i;
	}
	vector <pii> edge;
	for(int i = n-1; i >= 0; i--) {
		memset(vis, false, sizeof vis);
		for(int j = i+1; j < n; j++) {
			if(vis[p[j]] == false) {	
				// cout << p[i]+1 << " with " << p[j]+1 << endl;
				vector <int> tmp;
				for(int k = 0; k < i; k++) {
					tmp.emplace_back(p[k]);
				}
				for(int k = i+1; k <= j; k++) {
					if(vis[p[k]] == false) {
						tmp.emplace_back(p[k]);
					}
				}
				tmp.emplace_back(p[i]);
				for(int k = i+1; k < n; k++) {
					if(vis[p[k]] == false && k <= j) continue;
					tmp.emplace_back(p[k]);
				}
				if(query(tmp) == 0) {
					dfs(p[j]);
					edge.emplace_back(p[i], p[j]);
					// cerr << p[i]+1 << ' ' << p[j]+1 << endl;
				}
			}
		}
	}
	// cerr << cnt << endl;
	cout << "end" << endl;
	vector <int> ans (n);

	vector <int> small = order(edge);
	for(int i = 0; i < edge.size(); i++) {
		swap(edge[i].first, edge[i].second);
	}
	vector <int> big = order(edge);
	reverse(big.begin(), big.end());
	for(int i = 0; i < n; i++) {
		ans[small[i]] = i;
	}
	for(auto i : ans) {
		cout << i+1 << ' ';
	}
	cout << endl;
	for(int i = 0; i < n; i++) {
		ans[big[i]] = i;
	}
	for(auto i : ans) {
		cout << i+1 << ' ';
	}
	cout << endl;
	return 0;
}

Compilation message

zagonetka.cpp: In function 'std::vector<int> order(std::vector<std::pair<int, int> >)':
zagonetka.cpp:64:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < e.size(); i++) {
                 ~~^~~~~~~~~~
zagonetka.cpp: In function 'int main(int, const char**)':
zagonetka.cpp:121:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < edge.size(); i++) {
                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 436 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 544 KB Output is correct
2 Correct 43 ms 544 KB Output is correct
3 Correct 28 ms 568 KB Output is correct
4 Correct 38 ms 568 KB Output is correct
5 Correct 7 ms 576 KB Output is correct
6 Correct 42 ms 576 KB Output is correct
7 Correct 12 ms 576 KB Output is correct
8 Correct 12 ms 576 KB Output is correct
9 Correct 27 ms 700 KB Output is correct
10 Correct 19 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 700 KB Output is correct
2 Correct 6 ms 700 KB Output is correct
3 Correct 10 ms 700 KB Output is correct
4 Correct 8 ms 700 KB Output is correct
5 Correct 5 ms 700 KB Output is correct
6 Correct 11 ms 700 KB Output is correct
7 Correct 7 ms 700 KB Output is correct
8 Correct 13 ms 700 KB Output is correct
9 Correct 13 ms 700 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
11 Correct 15 ms 700 KB Output is correct
12 Correct 19 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 700 KB Output is correct
2 Correct 142 ms 712 KB Output is correct
3 Correct 66 ms 712 KB Output is correct
4 Correct 134 ms 860 KB Output is correct
5 Correct 126 ms 860 KB Output is correct
6 Correct 165 ms 912 KB Output is correct
7 Correct 107 ms 912 KB Output is correct
8 Correct 104 ms 912 KB Output is correct
9 Correct 102 ms 976 KB Output is correct
10 Correct 96 ms 976 KB Output is correct
11 Correct 94 ms 976 KB Output is correct
12 Correct 101 ms 976 KB Output is correct
13 Correct 125 ms 976 KB Output is correct
14 Correct 103 ms 976 KB Output is correct
15 Correct 141 ms 976 KB Output is correct
16 Correct 118 ms 976 KB Output is correct