Submission #202424

# Submission time Handle Problem Language Result Execution time Memory
202424 2020-02-16T04:29:51 Z EntityIT Library (JOI18_library) C++14
100 / 100
407 ms 504 KB
#include "library.h"
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

int n;
vector<int> pref;
bool query(int be, int en, int i) {
  vector<int> ele(n, 0);
  fill(ele.begin() + be, ele.begin() + en, 1);
  int prv = (be == en ? -1 : (be == 0 ? pref[en - 1] : Query(ele) ) );
  ele[i] = 1;
  int cur = Query(ele);
  return cur <= prv;
}

void Solve(int N) {
  n = N;
  pref.assign(n, 0);
  vector<int> cur(n, 0);
  for (int i = 0; i < n; ++i) {
    cur[i] = 1;
    pref[i] = Query(cur);
  }

  vector<vector<int> > gr(N);
  for (int i = 1; i < N; ++i) if (query(0, i, i) ) {
    int l = 0, r = i - 1;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (query(0, mid + 1, i) ) r = mid;
      else l = mid + 1;
    }

    gr[i].emplace_back(l);
    gr[l].emplace_back(i);

    if (query(l + 1, i, i) ) {
      int be = l + 1;
      l = be; r = i - 1;
      while (l < r) {
        int mid = (l + r) >> 1;
        if (query(be, mid + 1, i) ) r = mid;
        else l = mid + 1;
      }

      gr[i].emplace_back(l);
      gr[l].emplace_back(i);
    }
  }

  int rt = -1;
  for (int u = 0; u < N; ++u) if (sz(gr[u]) <= 1) rt = u;

  assert(rt != -1);
  vector<bool> vis(N);
  vector<int> ans;
  for (int u = rt; u != -1; ) {
    vis[u] = true;
    ans.emplace_back(u);

    int nxt = -1;
    for (int v : gr[u]) if (!vis[v]) nxt = v;
    u = nxt;
  }
  for (auto &i : ans) ++i;

  Answer(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 43 ms 248 KB # of queries: 2331
2 Correct 41 ms 248 KB # of queries: 2326
3 Correct 40 ms 376 KB # of queries: 2438
4 Correct 40 ms 248 KB # of queries: 2417
5 Correct 37 ms 248 KB # of queries: 2416
6 Correct 43 ms 248 KB # of queries: 2412
7 Correct 39 ms 248 KB # of queries: 2418
8 Correct 40 ms 376 KB # of queries: 2294
9 Correct 48 ms 328 KB # of queries: 2445
10 Correct 26 ms 248 KB # of queries: 1466
11 Correct 4 ms 252 KB # of queries: 1
12 Correct 5 ms 248 KB # of queries: 4
13 Correct 5 ms 248 KB # of queries: 9
14 Correct 6 ms 248 KB # of queries: 14
15 Correct 7 ms 376 KB # of queries: 96
16 Correct 8 ms 376 KB # of queries: 216
# Verdict Execution time Memory Grader output
1 Correct 43 ms 248 KB # of queries: 2331
2 Correct 41 ms 248 KB # of queries: 2326
3 Correct 40 ms 376 KB # of queries: 2438
4 Correct 40 ms 248 KB # of queries: 2417
5 Correct 37 ms 248 KB # of queries: 2416
6 Correct 43 ms 248 KB # of queries: 2412
7 Correct 39 ms 248 KB # of queries: 2418
8 Correct 40 ms 376 KB # of queries: 2294
9 Correct 48 ms 328 KB # of queries: 2445
10 Correct 26 ms 248 KB # of queries: 1466
11 Correct 4 ms 252 KB # of queries: 1
12 Correct 5 ms 248 KB # of queries: 4
13 Correct 5 ms 248 KB # of queries: 9
14 Correct 6 ms 248 KB # of queries: 14
15 Correct 7 ms 376 KB # of queries: 96
16 Correct 8 ms 376 KB # of queries: 216
17 Correct 399 ms 376 KB # of queries: 15269
18 Correct 383 ms 380 KB # of queries: 15130
19 Correct 394 ms 504 KB # of queries: 15359
20 Correct 369 ms 408 KB # of queries: 14392
21 Correct 347 ms 408 KB # of queries: 13478
22 Correct 407 ms 324 KB # of queries: 15429
23 Correct 404 ms 376 KB # of queries: 15297
24 Correct 156 ms 432 KB # of queries: 7171
25 Correct 385 ms 376 KB # of queries: 14970
26 Correct 353 ms 380 KB # of queries: 14028
27 Correct 145 ms 248 KB # of queries: 7228
28 Correct 290 ms 376 KB # of queries: 10976
29 Correct 278 ms 448 KB # of queries: 10964
30 Correct 267 ms 460 KB # of queries: 10976