Submission #212033

#TimeUsernameProblemLanguageResultExecution timeMemory
212033zimphaChameleon's Love (JOI20_chameleon)C++17
Compilation error
0 ms0 KiB
#include "chameleon.h" #include <cstdio> #include <cassert> #include <vector> std::vector<int> edges[N]; int col[N]; void dfs(int u, int c) { if (col[u] != -1) return; col[u] = c; for (auto &v: edges[u]) dfs(v, c ^ 1); } bool check(std::vector<int> v, int x) { v.push_back(x); return Query(v) == v.size(); } void Solve(int N) { for (int i = 1; i <= N * 2; ++i) { for (int j = 1; j < i; ++j) col[j] = -1; for (int j = 1; j < i; ++j) { if (col[j] == -1) dfs(j, 0); } std::vector<int> X, Y; for (int j = 1; j < i; ++j) { if (col[j] == 0) X.push_back(j); else Y.push_back(j); } for (int j = 0; j < 2; ++j) { while (!check(X, i)) { int left = 1, right = X.size(); while (left < right) { int mid = (left + right - 1) >> 1; if (!check({X.begin(), X.begin() + mid}, i)) right = mid; else left = mid + 1; } edges[i].push_back(X[left - 1]); edges[X[left - 1]].push_back(i); X = {X.begin() + left, X.end()}; } X.swap(Y); } } std::vector<int> mate(N * 2 + 1, -1); std::vector<int> love(N * 2 + 1, -1), loved(N * 2 + 1, -1); for (int i = 1; i <= N * 2; ++i) { if (edges[i].size() == 3) { int u1 = edges[i][0], u2 = edges[i][1], u3 = edges[i][2]; int v = -1; if (Query({u1, u2, i}) == 1) v = u3; if (Query({u2, u3, i}) == 1) v = u1; if (Query({u3, u1, i}) == 1) v = u2; love[i] = v; loved[v] = i; } else { mate[i] = edges[i][0]; } } for (int i = 1; i <= N * 2; ++i) if (edges[i].size() == 3) { assert(love[i] != -1 && loved[i] != -1); for (auto &x: edges[i]) { if (x != love[i] && x != loved[i]) mate[i] = x; } } for (int i = 1; i <= N * 2; ++i) { if (i < mate[i]) Answer(i, mate[i]); } }

Compilation message (stderr)

chameleon.cpp:6:24: error: 'N' was not declared in this scope
 std::vector<int> edges[N];
                        ^
chameleon.cpp:7:9: error: 'N' was not declared in this scope
 int col[N];
         ^
chameleon.cpp: In function 'void dfs(int, int)':
chameleon.cpp:10:7: error: 'col' was not declared in this scope
   if (col[u] != -1) return;
       ^~~
chameleon.cpp:10:7: note: suggested alternative: 'bool'
   if (col[u] != -1) return;
       ^~~
       bool
chameleon.cpp:11:3: error: 'col' was not declared in this scope
   col[u] = c;
   ^~~
chameleon.cpp:11:3: note: suggested alternative: 'bool'
   col[u] = c;
   ^~~
   bool
chameleon.cpp:12:17: error: 'edges' was not declared in this scope
   for (auto &v: edges[u]) dfs(v, c ^ 1);
                 ^~~~~
chameleon.cpp: In function 'bool check(std::vector<int>, int)':
chameleon.cpp:17:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   return Query(v) == v.size();
          ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:22:33: error: 'col' was not declared in this scope
     for (int j = 1; j < i; ++j) col[j] = -1;
                                 ^~~
chameleon.cpp:22:33: note: suggested alternative: 'bool'
     for (int j = 1; j < i; ++j) col[j] = -1;
                                 ^~~
                                 bool
chameleon.cpp:24:11: error: 'col' was not declared in this scope
       if (col[j] == -1) dfs(j, 0);
           ^~~
chameleon.cpp:24:11: note: suggested alternative: 'bool'
       if (col[j] == -1) dfs(j, 0);
           ^~~
           bool
chameleon.cpp:28:11: error: 'col' was not declared in this scope
       if (col[j] == 0) X.push_back(j);
           ^~~
chameleon.cpp:28:11: note: suggested alternative: 'bool'
       if (col[j] == 0) X.push_back(j);
           ^~~
           bool
chameleon.cpp:39:9: error: 'edges' was not declared in this scope
         edges[i].push_back(X[left - 1]);
         ^~~~~
chameleon.cpp:49:9: error: 'edges' was not declared in this scope
     if (edges[i].size() == 3) {
         ^~~~~
chameleon.cpp:52:22: error: 'u2' was not declared in this scope
       if (Query({u1, u2, i}) == 1) v = u3;
                      ^~
chameleon.cpp:52:22: note: suggested alternative: 'u1'
       if (Query({u1, u2, i}) == 1) v = u3;
                      ^~
                      u1
chameleon.cpp:52:28: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type '<brace-enclosed initializer list>'
       if (Query({u1, u2, i}) == 1) v = u3;
                            ^
In file included from chameleon.cpp:1:0:
chameleon.h:9:5: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
 int Query(const std::vector<int> &p);
     ^~~~~
chameleon.cpp:52:40: error: 'u3' was not declared in this scope
       if (Query({u1, u2, i}) == 1) v = u3;
                                        ^~
chameleon.cpp:52:40: note: suggested alternative: 'u1'
       if (Query({u1, u2, i}) == 1) v = u3;
                                        ^~
                                        u1
chameleon.cpp:53:18: error: 'u2' was not declared in this scope
       if (Query({u2, u3, i}) == 1) v = u1;
                  ^~
chameleon.cpp:53:18: note: suggested alternative: 'u1'
       if (Query({u2, u3, i}) == 1) v = u1;
                  ^~
                  u1
chameleon.cpp:53:22: error: 'u3' was not declared in this scope
       if (Query({u2, u3, i}) == 1) v = u1;
                      ^~
chameleon.cpp:53:22: note: suggested alternative: 'u1'
       if (Query({u2, u3, i}) == 1) v = u1;
                      ^~
                      u1
chameleon.cpp:53:28: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type '<brace-enclosed initializer list>'
       if (Query({u2, u3, i}) == 1) v = u1;
                            ^
In file included from chameleon.cpp:1:0:
chameleon.h:9:5: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
 int Query(const std::vector<int> &p);
     ^~~~~
chameleon.cpp:54:18: error: 'u3' was not declared in this scope
       if (Query({u3, u1, i}) == 1) v = u2;
                  ^~
chameleon.cpp:54:18: note: suggested alternative: 'u1'
       if (Query({u3, u1, i}) == 1) v = u2;
                  ^~
                  u1
chameleon.cpp:54:28: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type '<brace-enclosed initializer list>'
       if (Query({u3, u1, i}) == 1) v = u2;
                            ^
In file included from chameleon.cpp:1:0:
chameleon.h:9:5: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
 int Query(const std::vector<int> &p);
     ^~~~~
chameleon.cpp:54:40: error: 'u2' was not declared in this scope
       if (Query({u3, u1, i}) == 1) v = u2;
                                        ^~
chameleon.cpp:54:40: note: suggested alternative: 'u1'
       if (Query({u3, u1, i}) == 1) v = u2;
                                        ^~
                                        u1
chameleon.cpp:60:40: error: 'edges' was not declared in this scope
   for (int i = 1; i <= N * 2; ++i) if (edges[i].size() == 3) {
                                        ^~~~~