Submission #642060

# Submission time Handle Problem Language Result Execution time Memory
642060 2022-09-18T11:29:14 Z valerikk Library (JOI18_library) C++17
100 / 100
306 ms 336 KB
#include <cstdio>
#include <vector>
#include <cassert>
#include <iostream>

#include "library.h"

using namespace std;

void Solve(int n) {
  if (n == 1) {
    Answer({1});
    return;
  }

  vector<int> ends;
  for (int i = 0; i < n; ++i) {
    vector<int> a(n, 1);
    a[i] = 0;
    if (Query(a) == 1) {
      ends.push_back(i);
    }
  }

  assert(ends.size() == 2);
  
  vector<int> p(n);
  p[0] = ends[0];
  p[n - 1] = ends[1];

  vector<bool> used(n, false);
  used[p[0]] = true;
  used[p[n - 1]] = true;

  // cout << p[0] << " " << p[n - 1] << "\n";

  int l = 0, r = n - 1;
  while (l + 1 < r) {
    vector<int> a;
    for (int i = 0; i < n; ++i) {
      if (!used[i]) a.push_back(i);
    }

    if (l + 1 == r) {
      p[l + 1] = a[0];
      break;
    }

    int l_id = 0, r_id = 0;

    int sz = a.size();
    for (int t = 0; (1 << t) < sz; ++t) {
      vector<int> v(n, 0);
      for (int i = 0; i < sz; ++i) {
        if ((i >> t) & 1) v[a[i]] = 1;
      }

      int ans00 = Query(v);

      v[p[l]] = 1;
      int ans10 = Query(v);
      v[p[l]] = 0;

      v[p[r]] = 1;
      int ans01 = Query(v);
      v[p[r]] = 0;

      v[p[l]] = 1;
      v[p[r]] = 1;
      int ans11 = Query(v);
      v[p[l]] = 0;
      v[p[r]] = 0;

      if (ans00 == ans11) {
        l_id += 1 << t;
        r_id += 1 << t;
        continue;
      }

      if (ans00 + 2 == ans11) {
        continue;
      }

      assert(ans10 != ans01);

      if (ans10 < ans01) {
        l_id += 1 << t;
      } else {
        r_id += 1 << t;
      }
    } 

    ++l;
    --r;
    p[l] = a[l_id];
    p[r] = a[r_id];
    used[p[l]] = true;
    used[p[r]] = true;
  }

  for (int i = 0; i < n; ++i) {
    ++p[i];
  }
  Answer(p);
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 208 KB # of queries: 2724
2 Correct 33 ms 208 KB # of queries: 2719
3 Correct 37 ms 208 KB # of queries: 2860
4 Correct 38 ms 208 KB # of queries: 2860
5 Correct 23 ms 336 KB # of queries: 2860
6 Correct 26 ms 296 KB # of queries: 2860
7 Correct 39 ms 208 KB # of queries: 2860
8 Correct 39 ms 208 KB # of queries: 2753
9 Correct 33 ms 208 KB # of queries: 2855
10 Correct 18 ms 208 KB # of queries: 1665
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 3
14 Correct 0 ms 208 KB # of queries: 8
15 Correct 2 ms 208 KB # of queries: 95
16 Correct 4 ms 208 KB # of queries: 223
# Verdict Execution time Memory Grader output
1 Correct 34 ms 208 KB # of queries: 2724
2 Correct 33 ms 208 KB # of queries: 2719
3 Correct 37 ms 208 KB # of queries: 2860
4 Correct 38 ms 208 KB # of queries: 2860
5 Correct 23 ms 336 KB # of queries: 2860
6 Correct 26 ms 296 KB # of queries: 2860
7 Correct 39 ms 208 KB # of queries: 2860
8 Correct 39 ms 208 KB # of queries: 2753
9 Correct 33 ms 208 KB # of queries: 2855
10 Correct 18 ms 208 KB # of queries: 1665
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 2
13 Correct 0 ms 208 KB # of queries: 3
14 Correct 0 ms 208 KB # of queries: 8
15 Correct 2 ms 208 KB # of queries: 95
16 Correct 4 ms 208 KB # of queries: 223
17 Correct 285 ms 284 KB # of queries: 18916
18 Correct 262 ms 208 KB # of queries: 18701
19 Correct 287 ms 208 KB # of queries: 18916
20 Correct 257 ms 208 KB # of queries: 17698
21 Correct 286 ms 208 KB # of queries: 16685
22 Correct 229 ms 208 KB # of queries: 18916
23 Correct 306 ms 208 KB # of queries: 18911
24 Correct 126 ms 208 KB # of queries: 8705
25 Correct 191 ms 208 KB # of queries: 18491
26 Correct 276 ms 208 KB # of queries: 17315
27 Correct 107 ms 208 KB # of queries: 8667
28 Correct 229 ms 284 KB # of queries: 18916
29 Correct 304 ms 208 KB # of queries: 18911
30 Correct 291 ms 208 KB # of queries: 18916