답안 #45497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45497 2018-04-14T16:25:42 Z bogdan10bos 도서관 (JOI18_library) C++14
19 / 100
2000 ms 668 KB
#include <bits/stdc++.h>

using namespace std;

//#define DEBUG

#ifndef DEBUG
#include "library.h"
#endif // DEBUG

#ifdef DEBUG
int Query(const vector<int>& M);
void Answer(const vector<int>& res);
#endif

int _N;

int ask(vector<int> v)
{
    int N = _N;
    vector<int> f;
    f.resize(N);
    for(int i = 1; i <= N; i++)
        f[i - 1] = 0;
    for(auto x: v)
        f[x - 1] = 1;
    return Query(f);
}

void Solve(int N)
{
    if(N == 1)
    {
        vector<int> ans;
        ans.push_back(1);
        Answer(ans);
        return;
    }

    _N = N;
    vector<int> edg[1005];

    for(int i = 1; i <= N; i++) edg[i].clear();

    for(int i = 1; i <= N; i++)
        for(int j = i + 1; j <= N; j++)
        {
            vector<int> v;
            v.push_back(i);
            v.push_back(j);
            int ans = ask(v);
            if(ans == 1)
            {
                edg[i].push_back(j);
                edg[j].push_back(i);
            }
        }

    vector<int> ans;
    for(int i = 1; i <= N; i++)
        if(edg[i].size() == 1)
        {
            ans.push_back(i);
            ans.push_back(edg[i][0]);
            break;
        }
    for(int i = 3; i <= N; i++)
    {
        int x = ans[i - 2];
        int y = ans[i - 3];
        int nxt = y ^ edg[x][0] ^ edg[x][1];
        ans.push_back(nxt);
    }
    Answer(ans);

}

#ifdef DEBUG

namespace {
struct Judge
{
	int N;
	int A[1002];
	int pos[1002];
	bool f[1002];
	int query_c;
	bool answered;
	void init()
	{
	    freopen("1.in", "r", stdin);
		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();
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 294 ms 380 KB Output is correct
2 Correct 300 ms 500 KB Output is correct
3 Correct 304 ms 524 KB Output is correct
4 Correct 308 ms 528 KB Output is correct
5 Correct 294 ms 648 KB Output is correct
6 Correct 296 ms 660 KB Output is correct
7 Correct 301 ms 660 KB Output is correct
8 Correct 285 ms 660 KB Output is correct
9 Correct 308 ms 660 KB Output is correct
10 Correct 123 ms 668 KB Output is correct
11 Correct 2 ms 668 KB Output is correct
12 Correct 2 ms 668 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
14 Correct 2 ms 668 KB Output is correct
15 Correct 3 ms 668 KB Output is correct
16 Correct 7 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 294 ms 380 KB Output is correct
2 Correct 300 ms 500 KB Output is correct
3 Correct 304 ms 524 KB Output is correct
4 Correct 308 ms 528 KB Output is correct
5 Correct 294 ms 648 KB Output is correct
6 Correct 296 ms 660 KB Output is correct
7 Correct 301 ms 660 KB Output is correct
8 Correct 285 ms 660 KB Output is correct
9 Correct 308 ms 660 KB Output is correct
10 Correct 123 ms 668 KB Output is correct
11 Correct 2 ms 668 KB Output is correct
12 Correct 2 ms 668 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
14 Correct 2 ms 668 KB Output is correct
15 Correct 3 ms 668 KB Output is correct
16 Correct 7 ms 668 KB Output is correct
17 Execution timed out 2005 ms 668 KB Time limit exceeded
18 Halted 0 ms 0 KB -