Submission #1289198

#TimeUsernameProblemLanguageResultExecution timeMemory
1289198aegChameleon's Love (JOI20_chameleon)C++20
40 / 100
17 ms472 KiB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

void Solve(int N) {
  vector<set<int>> adj(N << 1);
  for (int i = 0; i < (N << 1); i++) {
    for (int j = i + 1; j < (N << 1); j++) {
      vector<int> toquer = {i + 1, j + 1};
      int ret = Query(toquer);
      if (ret == 1) {
        adj[i].insert(j);
        adj[j].insert(i);
      }
    }
  }

  vector<pair<int, int>> toign;

  for (int i = 0; i < (N << 1); i++) {
    if (adj[i].empty() || adj[i].size() == 1) {
      continue;
    } else {
      vector<int> tmp;
      for (auto x : adj[i])
        tmp.push_back(x);

      for (int k = 0; k < 3; k++) {
        vector<int> toask = {i + 1};
        for (int j = 0; j < 3; j++)
          if (j != k)
            toask.push_back(tmp[j] + 1);

        int ans = Query(toask);
        if (ans == 1) {
          toign.emplace_back(i, tmp[k]);
          break;
        }
      }
    }
  }

  for (auto &[x, y] : toign) {
    adj[x].erase(y);
    adj[y].erase(x);
  }

  for (int i = 0; i < (N << 1); i++) {
    if (adj[i].empty())
      continue;
    else {
      Answer(i + 1, (*adj[i].begin()) + 1);
      adj[*adj[i].begin()].clear();
      adj[i].clear();
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...