답안 #47851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47851 2018-05-08T08:44:52 Z mirbek01 도서관 (JOI18_library) C++17
0 / 100
57 ms 540 KB
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
void Solve(int N){
      vector <int> res(N), M(N), used(N), a(N), b(N);
      int cur = 0, p1 = 0;
      a[0] = 0;
      b[0] = 0;
      used[0] = 1;

      while(1){
            vector <int> v;
            for(int i = 0; i < N; i ++)
                  if(!used[i])
                        v.emplace_back(i);
            if(!v.size()) break;
            int lo = 0, hi = v.size() - 1;
            while(hi - lo > 1){
                  int md = (lo + hi) >> 1;
                  for(int i = 0; i <= md; i ++){
                        M[v[i]] = 1;
                  }
                  int A = Query(M);
                  M[cur] = 1;
                  int B = Query(M);
                  if(A == B)
                        hi = md;
                  else
                        lo = md;
                  M[cur] = 0;
                  for(int i = 0; i <= md; i ++)
                        M[v[i]] = 0;
            }
            for(int i = 0; i <= lo; i ++)
                  M[v[i]] = 1;
            int A = Query(M);
            M[cur] = 1;
            int B = Query(M);
            if(A == B) hi = lo;
            M[v[hi]] = 1;
            M[cur] = 0;
            A = Query(M);
            M[cur] = 1;
            B = Query(M);
            M[cur] = 0;
            for(int i = 0; i <= hi; i ++)
                  M[v[i]] = 0;
            if(A != B) break;
            used[v[hi]] = 1;
            a[++ p1] = v[hi];
            cur = v[hi];
      }
      cur = 0;
      int p2 = 0;
      while(1){
            vector <int> v;
            for(int i = 0; i < N; i ++)
                  if(!used[i])
                        v.emplace_back(i);
            if(!v.size()) break;
            int lo = 0, hi = v.size() - 1;
            while(hi - lo > 1){
                  int md = (lo + hi) >> 1;
                  for(int i = 0; i <= md; i ++){
                        M[v[i]] = 1;
                  }
                  int A = Query(M);
                  M[cur] = 1;
                  int B = Query(M);
                  if(A == B)
                        hi = md;
                  else
                        lo = md;
                  M[cur] = 0;
                  for(int i = 0; i <= md; i ++)
                        M[v[i]] = 0;
            }
            for(int i = 0; i <= lo; i ++)
                  M[v[i]] = 1;
            int A = Query(M);
            M[cur] = 1;
            int B = Query(M);
            if(A == B) hi = lo;
            M[v[hi]] = 1;
            M[cur] = 0;
            A = Query(M);
            M[cur] = 1;
            B = Query(M);
            M[cur] = 0;
            for(int i = 0; i <= hi; i ++)
                  M[v[i]] = 0;
            if(A != B) break;
            used[v[hi]] = 1;
            b[++ p2] = v[hi];
            cur = v[hi];
      }

      int ps = 0;
      for(int i = p2; i > 0; i --){
            res[ps ++] = b[i] + 1;
      }
      for(int i = 0; i <= p1; i ++){
            res[ps ++] = a[i] + 1;
      }
	Answer(res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 248 KB Output is correct
2 Correct 50 ms 308 KB Output is correct
3 Correct 57 ms 392 KB Output is correct
4 Correct 57 ms 392 KB Output is correct
5 Correct 53 ms 540 KB Output is correct
6 Correct 48 ms 540 KB Output is correct
7 Correct 56 ms 540 KB Output is correct
8 Correct 47 ms 540 KB Output is correct
9 Correct 51 ms 540 KB Output is correct
10 Incorrect 2 ms 540 KB Wrong Answer [5]
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 248 KB Output is correct
2 Correct 50 ms 308 KB Output is correct
3 Correct 57 ms 392 KB Output is correct
4 Correct 57 ms 392 KB Output is correct
5 Correct 53 ms 540 KB Output is correct
6 Correct 48 ms 540 KB Output is correct
7 Correct 56 ms 540 KB Output is correct
8 Correct 47 ms 540 KB Output is correct
9 Correct 51 ms 540 KB Output is correct
10 Incorrect 2 ms 540 KB Wrong Answer [5]
11 Halted 0 ms 0 KB -