답안 #710355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710355 2023-03-15T07:36:51 Z vjudge1 사육제 (CEOI14_carnival) C++17
100 / 100
26 ms 23884 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int pa[maxn];
int n;
vector<int>sz[maxn];
vector<int>q;
int ask(vector<int>s){
	cout<<s.size()<<" ";
	for(int i=0;i<s.size();i++){
		cout<<s[i]<<" ";
	}
	cout<<endl;
	int d;
	cin>>d;
	return d;
}
int find(int u,vector<int>d,int l,int r){
	vector<int>z=d;
	z.pb(u);
	int s=ask(z);
	if(r-l+1==d.size() && s==(int)(d.size())+1){
		return -1;
	}
	else{
		if(l==r){
			return l;
		}

		int mid=(l+r)/2;
		vector<int>k1;
		for(int i=l;i<=mid;i++){

			k1.pb(d[i]);
		}
		k1.pb(u);
		if(ask(k1)==mid-l+1){
			return find(u,d,l,mid);
		}
		else{
			return find(u,d,mid+1,r);
		}


	}
}
int fin(int a){
	if(a==pa[a])return a;
	return pa[a]=fin(pa[a]);
}
vector<int>divide(int l,int r){
    //cout<<l<<" "<<r<<"\n";
	vector<int>s;
	if(l==r){
		s.pb(l);
		return s;
	}
	int mid=(l+r)/2;

	vector<int>k1=divide(l,mid);
	vector<int>k2=divide(mid+1,r);

	for(auto u:k1){
		if((int)(k2.size())==0){
			break;
		}

		int z=find(u,k2,0,(int)(k2.size())-1);

		if(z!=-1){

			pa[k2[z]]=u;
			k2.erase(k2.begin()+z);
		}

	}
	for(auto v:k2){
		k1.pb(v);
	}

	return k1;

}

signed main()
{
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
    //freopen(task".inp" , "r" , stdin);
    //freopen(task".out" , "w" , stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
    	pa[i]=i;
    	sz[i].pb(i);
    }
    divide(1,n);

    vector<int>dinh;
    for(int i=1;i<=n;i++){
    	if(fin(i)==i){
    		dinh.pb(i);
    	}
    }
    cout<<"0"<<" ";
    for(int i=1;i<=n;i++){
    	int d=lower_bound(dinh.begin(),dinh.end(),pa[i])-dinh.begin()+1;
    	cout<<d<<" ";
    }
    cout<<endl;
    return 0;
}

Compilation message

carnival.cpp: In function 'int ask(std::vector<int>)':
carnival.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i=0;i<s.size();i++){
      |              ~^~~~~~~~~
carnival.cpp: In function 'int find(int, std::vector<int>, int, int)':
carnival.cpp:48:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  if(r-l+1==d.size() && s==(int)(d.size())+1){
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23820 KB Output is correct
2 Correct 16 ms 23760 KB Output is correct
3 Correct 22 ms 23816 KB Output is correct
4 Correct 19 ms 23828 KB Output is correct
5 Correct 14 ms 23760 KB Output is correct
6 Correct 14 ms 23760 KB Output is correct
7 Correct 22 ms 23768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23704 KB Output is correct
2 Correct 23 ms 23796 KB Output is correct
3 Correct 19 ms 23716 KB Output is correct
4 Correct 26 ms 23760 KB Output is correct
5 Correct 18 ms 23760 KB Output is correct
6 Correct 16 ms 23760 KB Output is correct
7 Correct 19 ms 23812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23760 KB Output is correct
2 Correct 19 ms 23736 KB Output is correct
3 Correct 24 ms 23760 KB Output is correct
4 Correct 19 ms 23816 KB Output is correct
5 Correct 17 ms 23760 KB Output is correct
6 Correct 14 ms 23816 KB Output is correct
7 Correct 24 ms 23804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23772 KB Output is correct
2 Correct 18 ms 23760 KB Output is correct
3 Correct 22 ms 23836 KB Output is correct
4 Correct 20 ms 23804 KB Output is correct
5 Correct 19 ms 23816 KB Output is correct
6 Correct 20 ms 23800 KB Output is correct
7 Correct 22 ms 23824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23760 KB Output is correct
2 Correct 21 ms 23884 KB Output is correct
3 Correct 24 ms 23816 KB Output is correct
4 Correct 23 ms 23760 KB Output is correct
5 Correct 20 ms 23760 KB Output is correct
6 Correct 19 ms 23712 KB Output is correct
7 Correct 20 ms 23760 KB Output is correct