Submission #421982

# Submission time Handle Problem Language Result Execution time Memory
421982 2021-06-09T14:26:36 Z juancarlovieri Zagonetka (COI18_zagonetka) C++17
27 / 100
3000 ms 328 KB
#include "bits/stdc++.h"
using namespace std;

#define kath ash

int n;
vector<int> p;

bool query(vector <int> v) {
  vector <int> p (v.size());
  for (size_t i = 0; i < v.size(); i++) {
    p[v[i]] = i;
  }
  cout << "query";
  for (auto i : p) {
    cout << " " << (i + 1);
  }
  cout << endl;
  int ans;
  cin >> ans;
  return ans;
}

vector <int> g[111];
bool vis[111];
void dfs(int x) {
  vis[x] = true;
  for (auto i : g[x]) {
    if (!vis[i]) {
      dfs(i);
    }
  }
}

int mx[105], mn[105], in[105];

void dp(int x) {
  mx[x] = mn[x] = x;
  for (auto i : g[x]) {
    if (!vis[i]) dp(i);
    mx[x] = max(mx[x], mx[i]);
    mn[x] = min(mn[x], mn[i]);
  }
}

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    p[x - 1] = i;
  }
  for (int i = n - 1; i >= 0; i--) {
    memset(vis, 0, sizeof vis);
    for (int j = i + 1; j < n; j++) {
      if (vis[p[j]] == 0) {
        vector <int> temp;
        for (int k = 0; k < i; k++) {
          temp.emplace_back(p[k]);
        }
        for (int k = i + 1; k <= j; k++) {
          if (vis[p[k]] == 0) {
            temp.emplace_back(p[k]);
          }
        }
        temp.emplace_back(p[i]);
        for (int k = i + 1; k < n; k++) {
          if (vis[p[k]] == 0 && k <= j) continue;
          temp.emplace_back(p[k]);
        }
        if (query(temp) == 0) {
          g[p[i]].emplace_back(p[j]);
          dfs(p[j]);
        }
      }
    }
  }
  cout << "end" << endl;

  memset(vis, 0, sizeof vis);
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dp(i);
    }
  }

  typedef pair <int, int> pii;
  priority_queue <pii> P;
  priority_queue <pii, vector <pii>, greater <pii>> Q;
  vector <int> small, big;

  memset(in, 0, sizeof in);
  for (int i = 0; i < n; i++) {
    for (int j : g[i]) {
      ++in[j];
    }
  }
  for (int i = 0; i < n; i++) {
    if (in[i] == 0) {
      Q.push(pii(mn[i], i));
      P.push(pii(i, i));
    }
  }
  while (!Q.empty()) {
    int x = Q.top().second;
    Q.pop();
    small.push_back(x);
    for (int i : g[x]) {
      --in[i];
      if (in[i] == 0) {
        Q.push(pii(mn[i], i));
      }
    }
  }
  memset(in, 0, sizeof in);
  for (int i = 0; i < n; i++) {
    for (int j : g[i]) {
      ++in[j];
    }
  }
  while (!P.empty()) {
    int x = P.top().second;
    P.pop();
    big.push_back(x);
    for (int i : g[x]) {
      --in[i];
      if (in[i] == 0) {
        P.push(pii(i, i));
      }
    }
  }

  vector <int> ans(n);
  for (int i = 0; i < n; i++) {
    ans[small[i]] = i;
  }
  for (int i : ans) {
    cout << i + 1 << ' ';
  }
  cout << endl;
  for (int i = 0; i < n; i++) {
    ans[big[i]] = i;
  }
  for (int i : ans) {
    cout << i + 1 << ' ';
  }
  cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 292 KB Output is correct
2 Correct 32 ms 296 KB Output is correct
3 Correct 38 ms 200 KB Output is correct
4 Correct 44 ms 200 KB Output is correct
5 Correct 12 ms 200 KB Output is correct
6 Correct 30 ms 308 KB Output is correct
7 Correct 7 ms 200 KB Output is correct
8 Correct 8 ms 200 KB Output is correct
9 Correct 34 ms 292 KB Output is correct
10 Correct 20 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 200 KB Output is correct
2 Incorrect 1 ms 200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 80 ms 200 KB Output is correct
2 Correct 101 ms 200 KB Output is correct
3 Correct 80 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 3 ms 200 KB Output is correct
6 Correct 3 ms 312 KB Output is correct
7 Execution timed out 3026 ms 204 KB Time limit exceeded
8 Halted 0 ms 0 KB -