답안 #217344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217344 2020-03-29T12:50:20 Z fedoseevtimofey 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
217 ms 12792 KB
#include "chameleon.h"
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
 
using namespace std;
 
typedef long long ll;
 
void Solve(int n) {
  vector <vector <int>> g(2 * n);
  
  int cnt_qr = 0;
  map <vector <int>, int> ans;
  function <int(vector <int>)> my_query = [&] (const vector <int> &p) {
    vector <int> a = p;
    sort(a.begin(), a.end());
    for (int &x : a) ++x;
    if (!ans.count(a)) {
      ++cnt_qr;
      ans[a] = Query(a);
    }
    return ans[a];
  };
  vector <int> col(2 * n, -1);
  function <void(int)> dfs = [&] (int u) {
    for (auto v : g[u]) {
      if (col[v] == -1) {
        col[v] = col[u] ^ 1;
        dfs(v);
      }
    }
  };  
  for (int v = 0; v < 2 * n; ++v) {
    if (!g[v].empty()) continue;
    fill(col.begin(), col.end(), -1);
    for (int i = 0; i < 2 * n; ++i) {
      if (col[i] == -1) {
        col[i] = 0;
        dfs(i);
      }
    }
    for (int t = 0; t < 2; ++t) {
      vector <int> q;
      for (int i = 0; i < v; ++i) if (col[i] == t) q.push_back(i);
      while (!q.empty()) {
        q.push_back(v);
        if (my_query(q) == (int)q.size()) break;
        q.pop_back();
        int l = 0, r = (int)q.size();
        while (r - l > 1) {
          int m = (l + r) >> 1;
          vector <int> a = vector <int> (q.begin(), q.begin() + m);
          a.push_back(v);
          if (my_query(a) == (int)a.size()) l = m;
          else r = m;
        }
        g[v].push_back(q[l]);
        g[q[l]].push_back(v);
        q = vector <int> (q.begin() + r, q.end());
      }
    } 
  }
 
  vector <int> who(2 * n, -1);
  vector <set <int>> bad(2 * n);
  for (int i = 0; i < 2 * n; ++i) {
    if (g[i].size() == 1) {
      who[i] = g[i][0];
      who[g[i][0]] = i;
    } else if (g[i].size() == 3) {
      for (int j = 0; j < 3; ++j) {
        vector <int> p = {i};
        for (int k = 0; k < 3; ++k) {
          if (k != j) p.push_back(g[i][k]);
        }
        if (my_query(p) == 1) {
          bad[i].insert(g[i][j]);
          bad[g[i][j]].insert(i);
        }
      }
    } else {
      assert(false);
    }
  }
  for (int i = 0; i < 2 * n; ++i) {
    if (who[i] == -1) {
      for (int j = 0; j < (int)g[i].size(); ++j) {
        if (!bad[i].count(g[i][j])) {
          who[i] = g[i][j];
        }
      }
    }
  }
 
  for (int i = 0; i < 2 * n; ++i) {
    if (who[i] > i) {
      Answer(i + 1, who[i] + 1);
    }
  }
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 157 ms 7672 KB Output is correct
4 Correct 153 ms 7672 KB Output is correct
5 Correct 162 ms 7644 KB Output is correct
6 Correct 161 ms 7800 KB Output is correct
7 Correct 158 ms 7672 KB Output is correct
8 Correct 156 ms 7672 KB Output is correct
9 Correct 160 ms 7928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 6 ms 432 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 7 ms 640 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 7 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 209 ms 12456 KB Output is correct
4 Correct 207 ms 12792 KB Output is correct
5 Correct 208 ms 12536 KB Output is correct
6 Correct 208 ms 12664 KB Output is correct
7 Correct 212 ms 12536 KB Output is correct
8 Correct 206 ms 12536 KB Output is correct
9 Correct 207 ms 12664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 157 ms 7672 KB Output is correct
4 Correct 153 ms 7672 KB Output is correct
5 Correct 162 ms 7644 KB Output is correct
6 Correct 161 ms 7800 KB Output is correct
7 Correct 158 ms 7672 KB Output is correct
8 Correct 156 ms 7672 KB Output is correct
9 Correct 160 ms 7928 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 6 ms 432 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 7 ms 640 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 209 ms 12456 KB Output is correct
31 Correct 207 ms 12792 KB Output is correct
32 Correct 208 ms 12536 KB Output is correct
33 Correct 208 ms 12664 KB Output is correct
34 Correct 212 ms 12536 KB Output is correct
35 Correct 206 ms 12536 KB Output is correct
36 Correct 207 ms 12664 KB Output is correct
37 Correct 173 ms 10872 KB Output is correct
38 Correct 157 ms 7672 KB Output is correct
39 Correct 178 ms 10976 KB Output is correct
40 Correct 176 ms 10872 KB Output is correct
41 Correct 175 ms 10872 KB Output is correct
42 Correct 156 ms 7672 KB Output is correct
43 Correct 217 ms 12772 KB Output is correct
44 Correct 172 ms 11000 KB Output is correct
45 Correct 173 ms 11000 KB Output is correct