답안 #699458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699458 2023-02-17T03:18:33 Z null_awe 도서관 (JOI18_library) C++14
100 / 100
450 ms 312 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include "library.h"
using namespace std;

void Solve(int n) {
  vector<int> front;
  vector<int> back;
  vector<int> left; for (int i = 0; i < n; ++i) left.push_back(i);
  while (left.size()) {
    int l = 0, r = left.size();
    while (l < r - 1) {
      int mid = (l + r) >> 1;
      vector<int> first(n), second(n);
      for (int i = 0; i < left.size(); ++i) {
        if (i >= l && i < mid) first[left[i]] = 1;
        else second[left[i]] = 1;
      }
      int q1 = Query(first), q2 = Query(second);
      if (q1 >= q2) r = mid;
      else l = mid;
    }
    int val = left[l];
    int ind = 0;
    for (int i = 0; i < left.size(); ++i) if (left[i] == val) ind = i;
    left.erase(left.begin() + ind);
    if (front.size()) {
      vector<int> arr(n);
      arr[front.back()] = 1, arr[val] = 1;
      int q = Query(arr);
      if (q == 1) front.push_back(val);
      else back.push_back(val);
    } else front.push_back(val);
  }
  vector<int> ans;
  for (int num : front) ans.push_back(num + 1);
  reverse(back.begin(), back.end());
  for (int num : back) ans.push_back(num + 1);
  // for (int num : ans) cout << num << ' ';
  // cout << '\n';
  Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:16:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |       for (int i = 0; i < left.size(); ++i) {
      |                       ~~^~~~~~~~~~~~~
library.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 0; i < left.size(); ++i) if (left[i] == val) ind = i;
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 208 KB # of queries: 2581
2 Correct 37 ms 208 KB # of queries: 2564
3 Correct 36 ms 284 KB # of queries: 2677
4 Correct 36 ms 208 KB # of queries: 2707
5 Correct 35 ms 208 KB # of queries: 2703
6 Correct 39 ms 212 KB # of queries: 2697
7 Correct 35 ms 284 KB # of queries: 2723
8 Correct 32 ms 208 KB # of queries: 2580
9 Correct 44 ms 280 KB # of queries: 2678
10 Correct 22 ms 212 KB # of queries: 1572
11 Correct 0 ms 212 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 3
13 Correct 1 ms 208 KB # of queries: 8
14 Correct 1 ms 208 KB # of queries: 13
15 Correct 1 ms 208 KB # of queries: 92
16 Correct 3 ms 208 KB # of queries: 212
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 208 KB # of queries: 2581
2 Correct 37 ms 208 KB # of queries: 2564
3 Correct 36 ms 284 KB # of queries: 2677
4 Correct 36 ms 208 KB # of queries: 2707
5 Correct 35 ms 208 KB # of queries: 2703
6 Correct 39 ms 212 KB # of queries: 2697
7 Correct 35 ms 284 KB # of queries: 2723
8 Correct 32 ms 208 KB # of queries: 2580
9 Correct 44 ms 280 KB # of queries: 2678
10 Correct 22 ms 212 KB # of queries: 1572
11 Correct 0 ms 212 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 3
13 Correct 1 ms 208 KB # of queries: 8
14 Correct 1 ms 208 KB # of queries: 13
15 Correct 1 ms 208 KB # of queries: 92
16 Correct 3 ms 208 KB # of queries: 212
17 Correct 394 ms 300 KB # of queries: 18153
18 Correct 427 ms 292 KB # of queries: 17978
19 Correct 450 ms 296 KB # of queries: 18101
20 Correct 391 ms 312 KB # of queries: 16945
21 Correct 336 ms 312 KB # of queries: 15944
22 Correct 420 ms 296 KB # of queries: 18173
23 Correct 442 ms 208 KB # of queries: 18108
24 Correct 146 ms 292 KB # of queries: 8334
25 Correct 412 ms 292 KB # of queries: 17744
26 Correct 351 ms 296 KB # of queries: 16508
27 Correct 143 ms 208 KB # of queries: 8282
28 Correct 383 ms 296 KB # of queries: 16973
29 Correct 398 ms 296 KB # of queries: 16954
30 Correct 405 ms 296 KB # of queries: 16973