답안 #152759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152759 2019-09-09T11:39:06 Z junodeveloper 사육제 (CEOI14_carnival) C++14
0 / 100
24 ms 424 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, par[151];
int T[1010];
int pn(int u){return u==par[u]?u:(par[u]=pn(par[u]));}
void us(int a,int b) {
	a=pn(a),b=pn(b);
	par[b]=a;
}
int query(int p,int l,int r) {
	printf("%d ",r-l+2);
	int i;
	printf("%d ",p);
	for(i=l;i<=r;i++) printf("%d ",i);
	fflush(stdout);
	int ret;
	scanf("%d",&ret);
	return ret;
}
void solve(int h,int l,int r) {
	if(l==r) {
		T[h]=1;
		return;
	}
	int mid=(l+r)/2;
	solve(h*2,l,mid);
	solve(h*2+1,mid+1,r);
	int i,ret;
	for(i=l;i<=mid;i++) {
		ret=query(i,mid+1,r);
		if(ret==T[h*2+1]+1) continue;
		else {
			int cur=h*2+1, tl=mid+1, tr=r;
			while(tl<tr) {
				int tmid=(tl+tr)/2;
				int tret=query(i,tl,tmid);
				if(tret==T[cur*2]+1) {
					tl=tmid+1;
					cur=cur*2+1;
				} else {
					tr=tmid;
					cur=cur*2;
				}
			}
			us(i,tl);
		}
	}
	vector<int> v;
	for(i=l;i<=r;i++)v.push_back(pn(i));
	sort(all(v));
	v.erase(unique(all(v)),v.end());
	T[h]=sz(v);
}
int main() {
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) par[i]=i;
	solve(1,1,n);
	printf("0 ");
	for(i=1;i<=n;i++) printf("%d ",par[i]);
	fflush(stdout);
	return 0;
}

Compilation message

carnival.cpp: In function 'int query(int, int, int)':
carnival.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&ret);
  ~~~~~^~~~~~~~~~~
carnival.cpp: In function 'int main()':
carnival.cpp:63: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 22 ms 248 KB Integer 19 violates the range [1, 11]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 320 KB Integer 6 violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 320 KB Output is correct
2 Incorrect 22 ms 424 KB Integer 11 violates the range [1, 8]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 320 KB Integer 5 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 324 KB Output is correct
2 Incorrect 13 ms 376 KB Integer 20 violates the range [1, 17]
3 Halted 0 ms 0 KB -