Submission #100930

# Submission time Handle Problem Language Result Execution time Memory
100930 2019-03-15T09:56:25 Z E869120 Carnival (CEOI14_carnival) C++14
100 / 100
41 ms 512 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n, col[155], cnts; vector<int>X[155];

int ask(vector<int>T) {
	cout << T.size();
	for (int i = 0; i < T.size(); i++) cout << " " << T[i]; cout << endl;
	int G; cin >> G;
	return G;
}

pair<int, int> solve(vector<int>vec) {
	int L1 = 0, R1 = vec.size(), M1, minx = (1 << 30);
	for (int i = 0; i < 10; i++) {
		M1 = (L1 + R1) / 2;
		vector<int>T; for (int j = 0; j <= M1; j++) T.push_back(vec[j]);
		int F = ask(T);
		if (F != T.size()) { minx = min(minx, M1); R1 = M1; }
		else { L1 = M1; }
	}

	if (minx == (1 << 30)) return make_pair(-1, -1);

	int L2 = 0, R2 = minx, M2, maxn = -1;
	for (int i = 0; i < 10; i++) {
		M2 = (L2 + R2) / 2;
		vector<int>T; for (int j = M2; j <= minx; j++) T.push_back(vec[j]);
		int F = ask(T);
		if (F != T.size()) { maxn = max(maxn, M2); L2 = M2; }
		else { R2 = M2; }
	}
	return make_pair(maxn, minx);
}

void dfs(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cnts;
	for (int i : X[pos]) dfs(i);
}

int main() {
	cin >> n;
	vector<int>vec; for (int i = 1; i <= n; i++) vec.push_back(i);

	while (true) {
		pair<int, int> E = solve(vec);
		if (E == make_pair(-1, -1)) break;
		X[vec[E.first]].push_back(vec[E.second]);
		X[vec[E.second]].push_back(vec[E.first]);

		vector<int>vec2;
		for (int i = 0; i < vec.size(); i++) {
			if (vec[E.first] == vec[i]) continue;
			vec2.push_back(vec[i]);
		}
		vec = vec2;
	}

	for (int i = 1; i <= n; i++) {
		if (col[i] >= 1) continue;
		cnts++; dfs(i);
	}
	cout << "0"; for (int i = 1; i <= n; i++) cout << " " << col[i]; cout << endl;
	return 0;
}

Compilation message

carnival.cpp: In function 'int ask(std::vector<int>)':
carnival.cpp:10:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < T.size(); i++) cout << " " << T[i]; cout << endl;
                  ~~^~~~~~~~~~
carnival.cpp:10:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for (int i = 0; i < T.size(); i++) cout << " " << T[i]; cout << endl;
  ^~~
carnival.cpp:10:58: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for (int i = 0; i < T.size(); i++) cout << " " << T[i]; cout << endl;
                                                          ^~~~
carnival.cpp: In function 'std::pair<int, int> solve(std::vector<int>)':
carnival.cpp:21:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (F != T.size()) { minx = min(minx, M1); R1 = M1; }
       ~~^~~~~~~~~~~
carnival.cpp:32:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (F != T.size()) { maxn = max(maxn, M2); L2 = M2; }
       ~~^~~~~~~~~~~
carnival.cpp: In function 'int main()':
carnival.cpp:55:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); i++) {
                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 324 KB Output is correct
2 Correct 26 ms 256 KB Output is correct
3 Correct 12 ms 304 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 22 ms 256 KB Output is correct
6 Correct 23 ms 256 KB Output is correct
7 Correct 20 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 384 KB Output is correct
2 Correct 31 ms 384 KB Output is correct
3 Correct 8 ms 332 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 21 ms 256 KB Output is correct
6 Correct 27 ms 384 KB Output is correct
7 Correct 25 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 412 KB Output is correct
2 Correct 28 ms 512 KB Output is correct
3 Correct 29 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 13 ms 384 KB Output is correct
6 Correct 19 ms 404 KB Output is correct
7 Correct 20 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 324 KB Output is correct
2 Correct 23 ms 328 KB Output is correct
3 Correct 12 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 12 ms 404 KB Output is correct
6 Correct 19 ms 432 KB Output is correct
7 Correct 41 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 384 KB Output is correct
2 Correct 31 ms 384 KB Output is correct
3 Correct 23 ms 256 KB Output is correct
4 Correct 17 ms 412 KB Output is correct
5 Correct 18 ms 256 KB Output is correct
6 Correct 8 ms 256 KB Output is correct
7 Correct 7 ms 256 KB Output is correct