답안 #617536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617536 2022-08-01T12:01:17 Z Ahmadsm2005 도서관 (JOI18_library) C++17
0 / 100
33 ms 472 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
bool E[1000][1000],VIS[1000];
int CNT[1000],NN;
void DFS(int v,int L,int R,int BL){
    if(VIS[v])return;
    VIS[v] = 1;
    for(int i = 0; i < NN; i += 1)if(E[i][v] && i >= L && i <= R && i != BL)DFS(i,L,R,BL);
}
int BS(int idx,int BL = -1){
    int L = 0, R = idx - 1 -(BL != -1), mid;
    while(L <= R){
        if(L == R){
            E[idx][L + (L >= BL && BL != -1)] = E[L + (L >= BL && BL != -1)][idx] = 1;
            CNT[idx]++,CNT[L + (L >= BL && BL != -1)]++;
            //cout<<L + 1 + (L >= BL && BL != -1)<<endl;
            return L + (L >= BL && BL != -1);
        }
        //cout<<L<<' '<<R<<endl;
        vector<int>F(NN,0);
        mid = (L + R) / 2;
        int Z = 0;
        for(int i = L; i <= mid; i += 1)F[i + (BL != -1 && i >= BL)] = 1;
        F[idx] = 1;
        for(int i = L; i <= mid; i += 1){
            //cout<<"Q: " <<i + (BL != -1 && i >= BL)<<endl;
            if(!VIS[i + (BL != -1 && i >= BL)])DFS(i + (BL != -1 && i >= BL),L,mid + (BL != -1 && mid >= BL),BL),Z++;
        }
        //cout<<"Z: "<<Z<<' '<<Query(F)<<endl;
        if(Z >= Query(F))R = mid;
        else L = mid + 1;
        for(int i = 0; i < NN; i += 1)VIS[i] = 0;
    }
}
void Solve(int N)
{
    NN = N;
	vector<int> M(N);
    M[0] = 1;
    int LST = 1;
	for(int i = 1; i < N; i += 1){
        M[i] = 1;
        int A = Query(M);
        if(A <= LST){
            //cout<<"Hmm: "<<i + 1<<endl;
            if(A == LST)BS(i);
            else{
                int Q = BS(i);
                //cout<<"BL: "<<Q<<endl;
                BS(i,Q);
            }
        }
        LST = A;
	}
	int S = 0, P = -1;
	for(int i = 0; i < N; i += 1)if(CNT[i] == 1){S = i;}
	vector<int> res;
	while(1){
        res.push_back(S + 1);
        //cout<<S + 1<<' ';
        for(int i = 0; i < N; i += 1)if(i != P && E[S][i]){P = S, S = i; goto a;}
        break;
        a:;
	}
	//cout<<res.size()<<endl;
	Answer(res);
}

Compilation message

library.cpp: In function 'int BS(int, int)':
library.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 464 KB # of queries: 1520
2 Correct 26 ms 416 KB # of queries: 1504
3 Correct 26 ms 428 KB # of queries: 1585
4 Incorrect 33 ms 472 KB Wrong Answer [4]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 464 KB # of queries: 1520
2 Correct 26 ms 416 KB # of queries: 1504
3 Correct 26 ms 428 KB # of queries: 1585
4 Incorrect 33 ms 472 KB Wrong Answer [4]
5 Halted 0 ms 0 KB -