Submission #539297

# Submission time Handle Problem Language Result Execution time Memory
539297 2022-03-18T16:20:22 Z Soumya1 Library (JOI18_library) C++17
0 / 100
33 ms 308 KB
#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
void Solve(int n) {
  int store[n + 1];
  {
      vector<int> q(n);
      for (int i = 1; i <= n; i++) {
          q[i - 1] = 1;
          store[i] = Query(q);
      }
  }
  vector<int> edge[n + 1];
  for (int i = 1; i <= n; i++) {
      int old_answer = store[i - 1];
      int new_answer = store[i];
      if (old_answer + 1 == new_answer) {
          continue;
      }
      int lo = 1, hi = i - 1;
      while (lo < hi) {
          int mid = (lo + hi) / 2;
          vector<int> q(n);
          for (int j = 1; j <= mid; j++) q[j - 1] = 1;
          q[i - 1] = 1;
          int x = store[mid];
          int y = Query(q);
          if (y > x) lo = mid + 1;
          else hi = mid;
      }
      edge[lo].push_back(i);
      edge[i].push_back(lo);
      if (new_answer < old_answer) {
          lo = 1, hi = i - 1;
          while (lo < hi) {
              int mid = (lo + hi) / 2;
              vector<int> q(n);
              for (int j = 1; j <= mid; j++) q[j - 1] = 1;
              q[i - 1] = 1;
              int x = store[mid];
              int y = Query(q);
              if (x <= y) lo = mid + 1;
              else hi = mid;
          }
          edge[lo].push_back(i);
          edge[i].push_back(lo);
      }
  }
  int start;
  for (int i = 1; i <= n; i++) {
      if ((int) edge[i].size() <= 1) start = i;
  }
  vector<bool> vis(n + 1);
  vector<int> ans;
  while ((int) ans.size() < n) {
      ans.push_back(start);
      vis[start] = true;
      for (int next : edge[start]) {
          if (!vis[next]) {
              start = next;
              break;
          }
      }
  }
  Answer(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 33 ms 288 KB # of queries: 1523
2 Correct 22 ms 208 KB # of queries: 1506
3 Correct 22 ms 296 KB # of queries: 1587
4 Correct 27 ms 220 KB # of queries: 1584
5 Correct 23 ms 296 KB # of queries: 1577
6 Correct 18 ms 308 KB # of queries: 1582
7 Correct 21 ms 216 KB # of queries: 1599
8 Correct 24 ms 308 KB # of queries: 1517
9 Correct 30 ms 304 KB # of queries: 1598
10 Correct 12 ms 212 KB # of queries: 940
11 Runtime error 1 ms 304 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 288 KB # of queries: 1523
2 Correct 22 ms 208 KB # of queries: 1506
3 Correct 22 ms 296 KB # of queries: 1587
4 Correct 27 ms 220 KB # of queries: 1584
5 Correct 23 ms 296 KB # of queries: 1577
6 Correct 18 ms 308 KB # of queries: 1582
7 Correct 21 ms 216 KB # of queries: 1599
8 Correct 24 ms 308 KB # of queries: 1517
9 Correct 30 ms 304 KB # of queries: 1598
10 Correct 12 ms 212 KB # of queries: 940
11 Runtime error 1 ms 304 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -