답안 #47877

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47877 2018-05-08T11:01:32 Z Just_Solve_The_Problem 도서관 (JOI18_library) C++14
0 / 100
89 ms 376 KB
#include <bits/stdc++.h>
//#include "grader.cpp"
#include "library.h"

#define pb push_back
#define ok cerr << "OK\n";

using namespace std;

const int NN = 1e3 + 7;

bool used[NN];

void solveSmall(int N) {
	vector < int > M(N, 0);
  vector < int > ans, vv;
  if (N == 1) {
    ans.pb(1);
    Answer(ans);
    return ;
  }
  deque < int > dq;
  int n = N;
  int cnt = 0;

  M[0] = 1;
  dq.pb(0);
  used[0] = 1;
  for (int i = 1; i < n; i++) {
    M[i] = 1;
    int qq = Query(M);
    if (qq == 1) {
      cnt++;
      vv.pb(i);
    }
    M[i] = 0;
  }
  M[0] = 0;
  used[vv[0]] = 1;
  dq.push_front(vv[0]);
  if (cnt == 2) {
    dq.push_back(vv[1]);
    used[vv[1]] = 1;
  }
  vv.clear();
  cnt++;
  while (cnt < n) {
    bool fl = 1;
    M[dq.back()] = 1;
    for (int j = 0; j < n; j++) {
      if (used[j]) continue;
      M[j] = 1;
      int qq = Query(M);
      M[j] = 0;
      if (qq == 1) {
        fl = 0;
        M[dq.back()] = 0;
        dq.pb(j);
        M[j] = 1;
        used[j] = 1;
        cnt++;
        break;
      }
    }
    M[dq.back()] = 0;
    if (fl) break;
  }
  for (int i = 0; i < n; i++) M[i] = 0;
  while (cnt < n) {
    bool fl = 1;
    M[dq.front()] = 1;
    for (int j = 0; j < n; j++) {
      if (used[j]) continue;
      M[j] = 1;
      int qq = Query(M);
      M[j] = 0;
      if (qq == 1) {
        fl = 0;
        M[dq.front()] = 0;
        dq.push_front(j);
        M[dq.front()] = 1;
        used[j] = 1;
        cnt++;
        break;
      }
    }
    if (fl) break;
  }
  for (int to : dq) {
    ans.pb(to + 1);
  }
	Answer(ans);
}

void Solve(int N) {
  vector < int > M(N, 1);
//  if (N <= 200) {
//    solveSmall(N);
//    return ;
//  }
  int n = N;
  vector < int > ans, v1, v2;
  int cnt = 0, qq;
  while (cnt < n - 1) {
    for (int i = 0; i < n && cnt < n - 1; i++) {
      if (used[i]) continue;
      M[i] = 0;
      qq = Query(M);
      M[i] = 1;
      if (qq == 1) {
        if (v1.empty()) {
          v1.pb(i);
        } else {
          M[v1.back()] = 1;
          M[i] = 0;
          qq = Query(M);
          M[v1.back()] = 0;
          if (qq == 1) {
            v2.pb(i);
          } else {
            v1.pb(i);
          }
        }
        used[i] = 1;
        cnt++;
        M[i] = 0;
      }
    }
    if (cnt >= n - 1) break;
    for (int i = n - 1; i >= 0 && cnt < n - 1; i--) {
      if (used[i]) continue;
      M[i] = 0;
      qq = Query(M);
      M[i] = 1;
      if (qq == 1) {
//        cout << i << endl;
        if (v1.empty()) {
          v1.pb(i);
        } else {
          M[v1.back()] = 1;
          qq = Query(M);
          M[v1.back()] = 0;
          if (qq != 1) {
            v2.pb(i);
          } else {
            v1.pb(i);
          }
        }
        used[i] = 1;
        cnt++;
        M[i] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      v1.pb(i);
      break;
    }
  }
  for (int to : v1) {
    ans.pb(to + 1);
  }
  for (int i = (int)v2.size() - 1; i >= 0; i--) {
    ans.pb(v2[i] + 1);
  }
  Answer(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 376 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 376 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -