Submission #909614

# Submission time Handle Problem Language Result Execution time Memory
909614 2024-01-17T09:50:39 Z MilosMilutinovic None (JOI16_memory2) C++14
100 / 100
1 ms 348 KB
#include "Memory2_lib.h"
#include <bits/stdc++.h>

using namespace std;

mt19937 rng(time(0));

void Solve(int t, int n) {
  n *= 2;
  vector<int> ids;
  ids.push_back(0);
  ids.push_back(1);
  ids.push_back(2);
  vector<vector<int>> val(n, vector<int>(n, -1));
  auto Ask = [&](int x, int y) {
    if (x == y) {
      return 0;
    }
    if (val[x][y] != -1) {
      return val[x][y];
    }
    val[x][y] = val[y][x] = Flip(x, y);
    return val[x][y];
  };
//  cout << Ask(0, 1) << '\n';
  vector<int> res(n, -1);
  for (int i = 3; i < n; i++) {
    ids.push_back(i);
    for (int x = 0; x < 4; x++) {
      set<int> st;
      for (int y = 0; y < 4; y++) {
        if (x != y) {
          st.insert(Ask(ids[x], ids[y]));
        }
      }
      if ((int) st.size() == 1) {
        res[ids[x]] = *st.begin();
        vector<int> new_ids;
        for (int y = 0; y < 4; y++) {
          if (x != y) {
            new_ids.push_back(ids[y]);
          }
        }
        ids = new_ids;
        break;
      }
    }
  }
  auto Output = [&]() {
    vector<vector<int>> f(n);
    for (int i = 0; i < n; i++) {
      f[res[i]].push_back(i);
    }
    for (int i = 0; i < n / 2; i++) {
      Answer(f[i][0], f[i][1], i);
    }
  };
//  for (int i = 0; i < n; i++) {
//    cout << res[i] << " ";
//  }
//  cout << '\n';
  vector<int> cnt(n);
  for (int i = 0; i < n; i++) {
    if (res[i] != -1) {
      cnt[res[i]] += 1;
    }
  }
  int mx = -1;
  for (int i = 0; i < n / 2; i++) {
    if (cnt[i] == 0) {
      mx = i;
      break;
    }
  }
  int el = -1;
  for (int i = 0; i < n / 2; i++) {
    if (cnt[i] == 1) {
      el = i;
      break;
    }
  }
//  cout << el << " " << mx << '\n';
  for (int x = 0; x < 3; x++) {
    set<int> st;
    for (int y = 0; y < 3; y++) {
      if (x != y) {
        st.insert(Ask(ids[x], ids[y]));
      }
    }
    if ((int) st.size() == 1) {
      res[ids[x]] = el;
      for (int y = 0; y < 3; y++) {
        if (x != y) {
          res[ids[y]] = mx;
        }
      }
      break;
    }
  }
  Output();
	return;
}

/*
1 3 10000
2 0 1
1 0 2 0 1 2

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct