답안 #786066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786066 2023-07-18T02:09:17 Z winter0101 도서관 (JOI18_library) C++14
0 / 100
17 ms 208 KB
#include<bits/stdc++.h>
#include "library.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
/*namespace {
struct Judge
{
	int N;
	int A[1002];
	int pos[1002];
	bool f[1002];
	int query_c;
	bool answered;
	void init()
	{
		query_c=0;
		int ret=scanf("%d",&N); ret++;
		answered=false;
		for(int i=0;i<N;i++)ret=scanf("%d",&A[i]),pos[A[i]]=i;
	}
	int query(const vector<int>& M)
	{
		if(query_c==20000)
		{
			puts("Wrong Answer [3]");
			exit(0);
		}
		if(int(M.size())!=N)
		{
			puts("Wrong Answer [1]");
			exit(0);
		}
		bool all_zero=true;
		for(int i=0;i<N;i++)
		{
			if(M[i]!=0&&M[i]!=1)
			{
				puts("Wrong Answer [2]");
				exit(0);
			}
			if(M[i]==1)all_zero=false;
		}
		if(all_zero)
		{
			puts("Wrong Answer [2]");
			exit(0);
		}
		memset(f,0,sizeof(f));
		for(int i=0;i<N;i++)if(M[i])f[pos[i+1]]=true;
		bool las=false;
		int r=0;
		for(int i=0;i<N;i++)
		{
			if(las==false&&f[i]==true)r++;
			if (f[i]){
                //cerr<<i+1<<'\n';
			}
			las=f[i];
		}
		query_c++;
		return r;
	}
	void answer(const vector<int>& res)
	{
		bool f1=true,f2=true;
		if(int(res.size())!=N)
		{
			puts("Wrong Answer [4]");
			exit(0);
		}
		if(answered)
		{
			puts("Wrong Answer [7]");
			exit(0);
		}
		answered=true;
		memset(f,0,sizeof(f));
		for(int i=0;i<N;i++)
		{
			if(res[i]<=0||res[i]>N)
			{
				puts("Wrong Answer [5]");
				exit(0);
			}
			if(f[res[i]])
			{
				puts("Wrong Answer [6]");
				exit(0);
			}
			f[res[i]]=true;
		}
		for(int i=0;i<N;i++)
		{
			f1&=A[i]==res[i];
			f2&=A[i]==res[N-i-1];
		}
		if(!f1&&!f2)
		{
			puts("Wrong Answer [8]");
			exit(0);
		}
	}
	void end()
	{
		if(!answered)puts("Wrong Answer [7]");
		else printf("Accepted : %d\n",query_c);
	}
}judge;
}

int Query(const vector<int>& M)
{
	return judge.query(M);
}
void Answer(const vector<int>& res)
{
	judge.answer(res);
}*/
bool use[1009];
void Solve(int n){
vector<vector<int>>gr;
gr.pb({1});
for1(i,2,n){
vector<int>t;
for1(j,1,i)t.pb(j);
vector<int>t1;
for1(j,1,n)use[j]=0;
for (auto v:t){
    use[v]=1;
}
for1(j,1,n){
t1.pb(use[j]);
}
int nans=Query(t1);
//cout<<i<<" "<<nans<<'\n';
if (nans==sz(gr)+1){
    gr.pb({i});
    continue;
}
else if (nans==sz(gr)){
    int l=0,r=sz(gr)-1,ans=r;
    //cerr<<l<<" "<<r<<'\n';
    while (l<=r){
        int mid=(l+r)/2;
        vector<int>tt;
        for1(j,0,mid){
        for(auto v:gr[j]){
            tt.pb(v);
        }
        }
        //cerr<<mid<<'\n';
        tt.pb(i);
        for1(j,1,n)use[j]=0;
        for (auto v:tt){
            use[v]=1;
        }
        vector<int>tt1;
        for1(j,1,n)tt1.pb(use[j]);
        int val=Query(tt1);
        if (val==mid+1){
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    if (sz(gr[ans])==1){
    gr[ans].pb(i);
    }
    else {
    vector<int>newask;
    for1(j,1,n)use[j]=0;
    use[i]=1;
    use[gr[ans].back()]=1;
    for1(j,1,n)newask.pb(use[j]);
    int n1=Query(newask);
    if (n1==2){
        reverse(all(gr[ans]));
        gr[ans].pb(i);
    }
    else {
        gr[ans].pb(i);
    }
    }
    //cerr<<ans<<'\n';
    continue;
}
else{
    int l=0,r=sz(gr)-1,ans=r;
    while (l<=r){
        int mid=(l+r)/2;
        vector<int>tt;
        for1(j,0,mid){
        for(auto v:gr[j]){
            tt.pb(v);
        }
        }
        tt.pb(i);
        vector<int>tt1;
        for1(j,1,n)use[j]=0;
        for (auto v:tt){
            use[v]=1;
        }
        for1(j,1,n)tt1.pb(use[j]);
        int val=Query(tt1);
        if (val<=mid+1){
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    //cerr<<ans<<'\n';
    l=ans+1,r=sz(gr)-1;
    int ano=r;
    while (l<=r){
        int mid=(l+r)/2;
        vector<int>tt;
        for1(j,0,mid){
        if (j==ans)continue;
        for(auto v:gr[j]){
            tt.pb(v);
        }
        }
        tt.pb(i);
        vector<int>tt1;
        for1(j,1,n)use[j]=0;
        for(auto v:tt){
            use[v]=1;
        }
        for1(j,1,n){
        tt1.pb(use[j]);
        }
        int val=Query(tt1);
        if (val<=mid){
            ano=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    vector<vector<int>>newgr;
    for1(j,0,sz(gr)-1){
        if (j==ano||j==ans){
          continue;
        }
        else {
          //if (j==ans)ans=sz(newgr);
          newgr.pb(gr[j]);
        }
    }
        vector<int>newask;
        for1(j,1,n){
        if (j==gr[ans].back()||j==i){
            newask.pb(1);
        }
        else newask.pb(0);
        }
        int lol=Query(newask);
        if (lol==1){
            gr[ans].pb(i);
            vector<int>a1;
            for1(j,1,n){
            if (j==i||j==gr[ano].back()){
                a1.pb(1);
            }
            else a1.pb(0);
            }
            int checkrev=Query(a1);
            if (checkrev==1){
                reverse(all(gr[ano]));
            }
            for (auto u:gr[ano]){
            gr[ans].pb(u);
            }
            newgr.pb(gr[ans]);
        }
        else {
            reverse(all(gr[ans]));
            gr[ans].pb(i);
            vector<int>a1;
            for1(j,1,n){
            if (j==i||j==gr[ano].back()){
                a1.pb(1);
            }
            else a1.pb(0);
            }
            int checkrev=Query(a1);
            if (checkrev==1){
                reverse(all(gr[ano]));
            }
            for (auto u:gr[ano]){
            gr[ans].pb(u);
            }
            newgr.pb(gr[ans]);
        }
    gr.swap(newgr);
    continue;
}
}
cout<<sz(gr)<<'\n';
for (auto v:gr){
    for(auto u:v){
        cout<<u<<" ";
    }
    cout<<'\n';
}
Answer(gr[0]);
}
/*signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen(".OUT","w",stdout);
    judge.init();
	Solve(judge.N);
	judge.end();
}*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 208 KB DO NOT WRITE ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 208 KB DO NOT WRITE ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -