Submission #640600

# Submission time Handle Problem Language Result Execution time Memory
640600 2022-09-15T03:07:08 Z SanguineChameleon Zagonetka (COI18_zagonetka) C++17
0 / 100
62 ms 304 KB
// BEGIN BOILERPLATE CODE

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

#ifdef KAMIRULEZ
	const bool kami_loc = true;
	const long long kami_seed = 69420;
#else
	const bool kami_loc = false;
	const long long kami_seed = chrono::steady_clock::now().time_since_epoch().count();
#endif

const string kami_fi = "kamirulez.inp";
const string kami_fo = "kamirulez.out";
mt19937_64 kami_gen(kami_seed);

long long rand_range(long long rmin, long long rmax) {
	uniform_int_distribution<long long> rdist(rmin, rmax);
	return rdist(kami_gen);
}

void file_io(string fi, string fo) {
	if (fi != "" && (!kami_loc || fi == kami_fi)) {
		freopen(fi.c_str(), "r", stdin);
	}
	if (fo != "" && (!kami_loc || fo == kami_fo)) {
		freopen(fo.c_str(), "w", stdout);
	}
}

void set_up() {
	if (kami_loc) {
		file_io(kami_fi, kami_fo);
	}
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void just_do_it();

void just_exec_it() {
	if (kami_loc) {
		auto pstart = chrono::steady_clock::now();
		just_do_it();
		auto pend = chrono::steady_clock::now();
		long long ptime = chrono::duration_cast<chrono::milliseconds>(pend - pstart).count();
		string bar(50, '=');
		cout << '\n' << bar << '\n';
		cout << "Time: " << ptime << " ms" << '\n';
	}
	else {
		just_do_it();
	}
}

int main() {
	set_up();
	just_exec_it();
	return 0;
}

// END BOILERPLATE CODE

// BEGIN MAIN CODE

const int ms = 1e2 + 20;
int a[ms];
int b[ms];
int c[ms];
int p[ms];
bool g[ms];
vector<int> adj1[ms];
vector<int> adj2[ms];
int de[ms];
int dz[ms];
int mi[ms];
int ma[ms];

void dfs(int u, bool f) {
	g[u] = true;
	for (auto v: adj1[u]) {
		if ((u > v) == f && !g[v]) {
			dfs(v, f);
		}
	}
}

void just_do_it() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		p[a[i]] = i;
	}
	for (int i = 1; i <= n - 1; i++) {
		for (int j = 1; j + i <= n; j++) {
			int lt = j;
			int rt = j + i;
			for (int k = lt; k <= rt; k++) {
				g[lt] = false;
			}
			vector<int> pp;
			dfs(rt, 1);
			if (g[lt]) {
				continue;
			}
			for (int k = lt; k <= rt; k++) {
				if (g[k]) {
					pp.push_back(k);
				}
				g[k] = false;
			}
			dfs(lt, 0);
			for (int k = lt; k <= rt; k++) {
				if (g[k]) {
					pp.push_back(k);
				}
				g[k] = false;
			}
			int pt = lt - 1;
			for (int k = 1; k <= lt - 1; k++) {
				b[k] = k;
			}
			for (int k = rt + 1; k <= n; k++) {
				b[k] = k;
			}
			for (int k = lt; k <= rt; k++) {
				b[k] = 0;
			}
			for (auto x: pp) {
				b[x] = ++pt;
			}
			for (int k = lt; k <= rt; k++) {
				if (!b[k]) {
					b[k] = ++pt;
				}
			}
			cout << "query ";
			for (int i = 1; i <= n; i++) {
				cout << b[a[i]] << " ";
			}
			cout << '\n';
			cout.flush();
			int d;
			cin >> d;
			if (d == 0) {
				adj2[p[rt]].push_back(p[lt]);
				de[p[lt]]++;
				adj1[lt].push_back(rt);
				adj1[rt].push_back(lt);
			}
		}
	}
	set<int> s;
	for (int i = 1; i <= n; i++) {
		dz[i] = de[i];
		if (dz[i] == 0) {
			s.insert(i);
		}
	}
	for (int i = n; i >= 1; i--) {
		int u = *s.rbegin();
		mi[u] = i;
		s.erase(u);
		for (auto v: adj2[u]) {
			dz[v]--;
			if (dz[v] == 0) {
				s.insert(v);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		dz[i] = de[i];
		if (dz[i] == 0) {
			s.insert(i);
		}
	}
	for (int i = n; i >= 1; i--) {
		int u = *s.begin();
		ma[u] = i;
		s.erase(u);
		for (auto v: adj2[u]) {
			dz[v]--;
			if (dz[v] == 0) {
				s.insert(v);
			}
		}
	}
	cout << "end" << '\n';
	cout.flush();
	for (int i = 1; i <= n; i++) {
		cout << mi[i] << " ";
	}
	cout << '\n';
	cout.flush();
	for (int i = 1; i <= n; i++) {
		cout << ma[i] << " ";
	}
	cout << '\n';
	cout.flush();
}

// END MAIN CODE

Compilation message

zagonetka.cpp: In function 'void file_io(std::string, std::string)':
zagonetka.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen(fi.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zagonetka.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   freopen(fo.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Output is correct
2 Runtime error 1 ms 208 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -