Submission #534625

# Submission time Handle Problem Language Result Execution time Memory
534625 2022-03-08T12:11:28 Z shrimb Carnival (CEOI14_carnival) C++17
0 / 100
49 ms 200 KB
#include"bits/stdc++.h"
#define int long long
// #define endl '\n'
using namespace std;

int dsu[2000001];
int ans[2000001];

int Find (int x) {
	return dsu[x] == x ? x : dsu[x] = Find(dsu[x]);
}

void Union (int a, int b) {
	dsu[Find(a)] = Find(b);
}

bool Query (int a, int b) {
	cout << "2 " << a << " " << b << endl;
	int x;
	cin >> x;
	return x == 1;
}


signed main () {

	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; i++) dsu[i] = i;
	for (int i = 1 ; i <= n ; i++) {
		bitset<151> vis;
		vis[i] = 1;
		for (int j = 0 ; j < 30 ; j++) {
			int x = rand() % n + 1;
			if (vis[x]) {j-=(vis.count() < n); continue;}
			else {
				vis[x] = 1;
				if (Query(i, x)) Union(i, x);
			}
		}
	}

	int c = 1;
	for (int i = 1 ; i <= n ; i++) if (dsu[i] == i) ans[i] = c++;
	cout << 0 << " ";
	for (int i = 1 ; i <= n ; i++) cout << ans[Find(i)] << " ";
}

Compilation message

carnival.cpp: In function 'int main()':
carnival.cpp:35:33: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |    if (vis[x]) {j-=(vis.count() < n); continue;}
      |                     ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Partially correct 39 ms 200 KB Partially correct
2 Incorrect 29 ms 200 KB Integer 48 violates the range [1, 37]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 34 ms 200 KB Partially correct
2 Incorrect 49 ms 200 KB Integer 34 violates the range [1, 28]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 23 ms 200 KB Partially correct
2 Partially correct 45 ms 200 KB Partially correct
3 Incorrect 30 ms 200 KB Integer 77 violates the range [1, 58]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 46 ms 200 KB Partially correct
2 Partially correct 44 ms 200 KB Partially correct
3 Incorrect 47 ms 200 KB Integer 123 violates the range [1, 120]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 38 ms 200 KB Partially correct
2 Incorrect 43 ms 200 KB Integer 18 violates the range [1, 17]
3 Halted 0 ms 0 KB -