답안 #25909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25909 2017-06-25T05:40:44 Z 김동현(#1086) 사육제 (CEOI14_carnival) C++14
0 / 100
9 ms 2024 KB
#include <bits/stdc++.h>
using namespace std;

int n, p[151];

int fnd(int x){ return p[x] = (x == p[x] ? x : fnd(p[x])); }
void uni(int x, int y){ p[fnd(x)] = fnd(y); }

vector<int> f(int s, int e){
	if(s == e){
		vector<int> ret; ret.push_back(s);
		return ret;
	}
	vector<int> l = f(s, (s + e) / 2);
	vector<int> r = f((s + e) / 2 + 1, e);
	int rs = r.size();
	vector<int> ret;
	for(auto &i : l){
		printf("%d %d ", rs + 1, i);
		for(auto &j : r) printf("%d ", j);
		puts(""); fflush(stdout);
		int t; scanf("%d", &t);
		if(t == rs + 1){
			ret.push_back(i);
			continue;
		}
		int s = 0, e = r.size() - 1;
		while(s < e){
			int m = (s + e) / 2;
			printf("%d %d ", m - s + 2, i);
			for(int j = s; j <= m; j++) printf("%d ", r[j]);
			puts(""); fflush(stdout);
			scanf("%d", &t);
			if(t < m - s + 2) e = m;
			else s = m + 1;
		}
		uni(i, r[s]);
	}
	for(auto &i : r) ret.push_back(i);
	return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) p[i] = i;
	f(1, n);
	set<int> ss;
	int cnt, c[151];
	for(int i = 1; i <= n; i++){
		if(ss.find(fnd(i)) != ss.end()) continue;
		ss.insert(fnd(i));
		c[fnd(i)] = ++cnt;
	}
	printf("0 ");
	for(int i = 1; i <= n; i++)	printf("%d ", c[fnd(i)]);
	fflush(stdout);
}

Compilation message

carnival.cpp: In function 'std::vector<int> f(int, int)':
carnival.cpp:22:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int t; scanf("%d", &t);
                         ^
carnival.cpp:33:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &t);
                   ^
carnival.cpp: In function 'int main()':
carnival.cpp:44:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
carnival.cpp:52:20: warning: 'cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   c[fnd(i)] = ++cnt;
                    ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2024 KB Integer 4831089 violates the range [1, 11]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Integer 4831089 violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2024 KB Integer 4831089 violates the range [1, 1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Integer 4831089 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Integer 4831089 violates the range [1, 2]
2 Halted 0 ms 0 KB -