답안 #1021994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021994 2024-07-13T08:43:25 Z davit_tsibadze 도서관 (JOI18_library) C++17
100 / 100
221 ms 444 KB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
// 4 2 5 3 1
const ll inf = 1e18;
// #define int long long
int d;
vector <int> ans, m, a;
// 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);
// }
 
 
bool isgood(int mid){
    for (int i = 0; i < (int)m.size(); i++)
        m[i] = 0;
    for (int i = 0; i <= mid; i++)
        m[a[i] - 1] = 1;
    int x = Query(m);
    m[ans.back() - 1] = 1;
    return (x == Query(m));
}
void Solve(int N){
    bool used[N + 1] = {};
    while((int)m.size() < N)m.pb(1);
    if (N == 1){
        ans.pb(1);
        Answer(ans);
        return;
    }
    for (int i = 1; i <= N; i++){
        m[i - 1] = 0;
        if (Query(m) == 1){d = i; break;}
        m[i - 1] = 1;
    }
    ans.pb(d); used[d] = true;
    while((int)ans.size() < N){
        a.clear();
        for (int i = 1; i <= N; i++) if (!used[i])a.pb(i); 
        int l = 0, r = a.size() - 1, mid, answ = 0;
        while(l <= r){
            mid = (l + r) / 2;
            if (isgood(mid)) {
                answ = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        ans.pb(a[answ]); used[a[answ]] = true;
    }
    Answer(ans);
}
 
// int main()
// {
// 	judge.init();
// 	Solve(judge.N);
// 	judge.end();
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 344 KB # of queries: 2401
2 Correct 13 ms 344 KB # of queries: 2437
3 Correct 22 ms 344 KB # of queries: 2658
4 Correct 17 ms 344 KB # of queries: 2597
5 Correct 24 ms 344 KB # of queries: 2526
6 Correct 28 ms 344 KB # of queries: 2565
7 Correct 14 ms 344 KB # of queries: 2556
8 Correct 16 ms 344 KB # of queries: 2424
9 Correct 24 ms 344 KB # of queries: 2550
10 Correct 11 ms 344 KB # of queries: 1488
11 Correct 1 ms 344 KB # of queries: 0
12 Correct 1 ms 344 KB # of queries: 3
13 Correct 0 ms 344 KB # of queries: 6
14 Correct 0 ms 344 KB # of queries: 9
15 Correct 1 ms 344 KB # of queries: 79
16 Correct 1 ms 344 KB # of queries: 195
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 344 KB # of queries: 2401
2 Correct 13 ms 344 KB # of queries: 2437
3 Correct 22 ms 344 KB # of queries: 2658
4 Correct 17 ms 344 KB # of queries: 2597
5 Correct 24 ms 344 KB # of queries: 2526
6 Correct 28 ms 344 KB # of queries: 2565
7 Correct 14 ms 344 KB # of queries: 2556
8 Correct 16 ms 344 KB # of queries: 2424
9 Correct 24 ms 344 KB # of queries: 2550
10 Correct 11 ms 344 KB # of queries: 1488
11 Correct 1 ms 344 KB # of queries: 0
12 Correct 1 ms 344 KB # of queries: 3
13 Correct 0 ms 344 KB # of queries: 6
14 Correct 0 ms 344 KB # of queries: 9
15 Correct 1 ms 344 KB # of queries: 79
16 Correct 1 ms 344 KB # of queries: 195
17 Correct 221 ms 432 KB # of queries: 18030
18 Correct 201 ms 424 KB # of queries: 17279
19 Correct 208 ms 432 KB # of queries: 17479
20 Correct 193 ms 444 KB # of queries: 16301
21 Correct 174 ms 432 KB # of queries: 15352
22 Correct 214 ms 432 KB # of queries: 17663
23 Correct 208 ms 428 KB # of queries: 17250
24 Correct 82 ms 428 KB # of queries: 7917
25 Correct 212 ms 424 KB # of queries: 17158
26 Correct 175 ms 444 KB # of queries: 16003
27 Correct 80 ms 344 KB # of queries: 8046
28 Correct 212 ms 424 KB # of queries: 15975
29 Correct 189 ms 428 KB # of queries: 15957
30 Correct 187 ms 424 KB # of queries: 15975