답안 #48073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48073 2018-05-10T02:50:51 Z kawaiigrabrielneko 도서관 (JOI18_library) C++14
100 / 100
489 ms 668 KB
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;

void Solve(int N){
	vector<int> A(N);
	vector<int> B(N);
	vector<int> AP(N);
	vector<int> AMB(N);
	vector<int> APUB(N);
	int na = N/2;
	vector<int> ans(N);
	if (N==1){
        A[0] = 1;
        Answer(A);
        return;
	}
	for (int i = 0; i < N/2; i++){
        A[i] = 1;
        AP[i] = 0;
	}
	for (int i = N/2; i < N; i++){
        A[i] = 0;
        AP[i] = 1;
	}
	if (Query(A)<Query(AP)){
        for (int i = 0; i < N; i++){
            A[i] = 1 - A[i];
            AP[i] = 1 - AP[i];
        }
        na = N - na;
	}
	// A contains an endpoint
	while (na > 1){
        int nb = na/2;
        int ct = 0;
        for (int i = 0; i < N; i++){
            if (A[i]==1&&ct<nb){
                B[i] = 1;
                ct++;
            }
            else B[i] = 0;
            AMB[i] = A[i] - B[i];
            APUB[i] = 1 - AMB[i];
        }
        if (Query(AMB)<Query(APUB)){ // Endpoint in B
            for (int i = 0; i < N; i++){
                A[i] = B[i];
            }
            na = nb;
        }
        else { // Endpoint in A - B
            for (int i = 0; i < N; i++){
                A[i] = AMB[i];
            }
            na = na - nb;
        }
	}
	for (int i = 0; i < N; i++){
        if (A[i] == 1) ans[0] = i;
	}
	vector<int> M(N);
	vector<int> K(N);
	for (int i = 1; i < N; i++){
        int nm = N-i;
        for (int j = 0; j < N; j++){
            M[j] = 1;
        }
        for (int j = 0; j < i; j++){
            M[ans[j]] = 0;
        }
        while (nm > 1){
            int nk = nm/2;
            int ct = 0;
            for (int j = 0; j < N; j++){
                if (M[j]==1&&ct<nk){
                    ct++;
                    K[j] = 1;
                }
                else K[j] = 0;
            }
            int x = Query(K);
            K[ans[i-1]] = 1;
            if (x==Query(K)){
                K[ans[i-1]] = 0;
                nm = nk;
                for (int j = 0; j < N; j++){
                    M[j] = K[j];
                }
            }
            else {
                K[ans[i-1]] = 0;
                nm = nm - nk;
                for (int j = 0; j < N; j++){
                    M[j] = M[j] - K[j];
                }
            }
        }
        for (int j = 0; j < N; j++){
            if (M[j]==1) ans[i] = j;
        }
	}
	for (int i = 0; i < N; i++){
        ans[i]++;
	}
	Answer(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 388 KB Output is correct
2 Correct 38 ms 440 KB Output is correct
3 Correct 26 ms 440 KB Output is correct
4 Correct 28 ms 440 KB Output is correct
5 Correct 26 ms 484 KB Output is correct
6 Correct 38 ms 488 KB Output is correct
7 Correct 38 ms 540 KB Output is correct
8 Correct 25 ms 668 KB Output is correct
9 Correct 39 ms 668 KB Output is correct
10 Correct 21 ms 668 KB Output is correct
11 Correct 1 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 2 ms 668 KB Output is correct
16 Correct 4 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 388 KB Output is correct
2 Correct 38 ms 440 KB Output is correct
3 Correct 26 ms 440 KB Output is correct
4 Correct 28 ms 440 KB Output is correct
5 Correct 26 ms 484 KB Output is correct
6 Correct 38 ms 488 KB Output is correct
7 Correct 38 ms 540 KB Output is correct
8 Correct 25 ms 668 KB Output is correct
9 Correct 39 ms 668 KB Output is correct
10 Correct 21 ms 668 KB Output is correct
11 Correct 1 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 2 ms 668 KB Output is correct
16 Correct 4 ms 668 KB Output is correct
17 Correct 430 ms 668 KB Output is correct
18 Correct 460 ms 668 KB Output is correct
19 Correct 484 ms 668 KB Output is correct
20 Correct 416 ms 668 KB Output is correct
21 Correct 401 ms 668 KB Output is correct
22 Correct 489 ms 668 KB Output is correct
23 Correct 489 ms 668 KB Output is correct
24 Correct 156 ms 668 KB Output is correct
25 Correct 465 ms 668 KB Output is correct
26 Correct 448 ms 668 KB Output is correct
27 Correct 153 ms 668 KB Output is correct
28 Correct 433 ms 668 KB Output is correct
29 Correct 397 ms 668 KB Output is correct
30 Correct 416 ms 668 KB Output is correct