Submission #549197

# Submission time Handle Problem Language Result Execution time Memory
549197 2022-04-15T11:49:23 Z krit3379 Library (JOI18_library) C++17
Compilation error
0 ms 0 KB
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
using namespace std;
void Solve(int N);

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++;
			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);
}

int main()
{
	judge.init();
	Solve(judge.N);
	judge.end();
}

#include<bits/stdc++.h>
using namespace std;
#define N 1005

bitset<N> vis;
vector<int> now,ans;

void Solve(int n){
    if(n==1){
        ans.push_back(1);
        Answer(ans);
        return ;
    }
    int i,sz,x,y,head,l,r,mid,cnt;
    now.resize(n);
    for(i=0;i<n;i++)now[i]=1;
    for(i=0;i<n;i++){
        now[i]=0;
        x=Query(now);
        now[i]=1;
        if(x==1){head=i;break;}
    }
    for(i=0;i<n;i++)now[i]=0;
    vis[head]=true;
    ans.push_back(head+1);
    for(sz=n-1;sz>0;sz--){
        l=1,r=sz;
        while(l<r){
            mid=(l+r)/2;
            for(i=0,cnt=0;i<n&&cnt<mid;i++)if(!vis[i])now[i]=1,cnt++;
            x=Query(now);
            now[head]=1;
            y=Query(now);
            now[head]=0;
            for(i=0,cnt=0;i<n&&cnt<mid;i++)if(!vis[i])now[i]=0,cnt++;
            if(x==y)r=mid;
            else l=mid+1;
        }
        for(i=0,cnt=0;i<n&&cnt<l;i++)if(!vis[i])cnt++;
        ans.push_back(i);
        head=i-1;
        vis[head]=true;
    }
    Answer(ans);
    return ;
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:151:23: warning: 'head' may be used uninitialized in this function [-Wmaybe-uninitialized]
  151 |     ans.push_back(head+1);
      |                   ~~~~^~
/usr/bin/ld: /tmp/ccLu3q9Q.o: in function `Query(std::vector<int, std::allocator<int> > const&)':
library.cpp:(.text+0x0): multiple definition of `Query(std::vector<int, std::allocator<int> > const&)'; /tmp/ccSrRqoU.o:grader.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccLu3q9Q.o: in function `Answer(std::vector<int, std::allocator<int> > const&)':
library.cpp:(.text+0x180): multiple definition of `Answer(std::vector<int, std::allocator<int> > const&)'; /tmp/ccSrRqoU.o:grader.cpp:(.text+0x20): first defined here
/usr/bin/ld: /tmp/ccLu3q9Q.o: in function `main':
library.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccSrRqoU.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status