답안 #112827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112827 2019-05-22T06:30:28 Z Firastic 사육제 (CEOI14_carnival) C++14
0 / 100
37 ms 512 KB
#include <bits/stdc++.h>
using namespace std;

int n,visited[200][200];
int done[200],p[200],ans[200];

int cari(int x){
	if(p[x] == x)return x;
	p[x] = cari(p[x]);
	return p[x];
}

void gabung(int x, int y){
	if(cari(x) != cari(y)){
		p[cari(y)] = cari(x);
	}
}

void ask(){
	int x,y;
	int ans;
	do{
		x = rand()%n;
		do{
			y = rand()%n;
		} while(y==x);
		if(x>y)swap(x,y);
	} while(visited[x][y]);

	printf("2 %d %d\n", x+1, y+1);
	fflush(stdout);
	visited[x][y] = true;

	scanf("%d", &ans);
	ans--;
	ans = !ans;
	if(ans){
		gabung(x,y);
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		p[i] = i;
	}
	for(int i = 0; i < min(n*(n-1)/2,3500); i++){
		ask();
	}
	int cur = 0;
	for(int i = 0; i < n; i++){
		if(!done[i]){
			done[i] = true;
			cur++;
			for(int j = i; j < n; j++){
				if(cari(i) == cari(j)){
					done[j] = true;
					ans[j] = cur;
				}
			}
		}
	}
	printf("0 ");
	for(int i = 0; i < n; i++){
		printf("%d", ans[i]);
		if(i==n-1)printf("\n");
		else printf(" ");
	}
	fflush(stdout);
}

Compilation message

carnival.cpp: In function 'void ask()':
carnival.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &ans);
  ~~~~~^~~~~~~~~~~~
carnival.cpp: In function 'int main()':
carnival.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 384 KB Integer 12 violates the range [1, 11]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 384 KB Output is correct
2 Incorrect 12 ms 416 KB Integer 29 violates the range [1, 28]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Incorrect 31 ms 428 KB Integer 59 violates the range [1, 58]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 416 KB Output is correct
2 Correct 12 ms 416 KB Output is correct
3 Incorrect 26 ms 384 KB Integer 121 violates the range [1, 120]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 512 KB Output is correct
2 Incorrect 37 ms 432 KB Integer 18 violates the range [1, 17]
3 Halted 0 ms 0 KB -