Submission #937783

#TimeUsernameProblemLanguageResultExecution timeMemory
937783PringChameleon's Love (JOI20_chameleon)C++17
100 / 100
39 ms604 KiB
#include <bits/stdc++.h> #include "chameleon.h" using namespace std; #define fs first #define sc second #define mp make_pair #define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++) typedef pair<int, int> pii; const int MXN = 1005; vector<int> edge[MXN]; set<pii> S; void BSH(vector<int> v, int x) { auto check = [&]() -> bool { v.push_back(x); bool f = (Query(v) != v.size()); v.pop_back(); return f; }; do { int l = 0, r = v.size(); while (l + 1 < r) { int mid = (l + r) >> 1; // printf("%d %d\n", l, r); vector<int> w(mid); copy(v.begin(), v.begin() + mid, w.begin()); w.push_back(x); (Query(w) != w.size() ? r : l) = mid; } edge[x].push_back(v[l]); edge[v[l]].push_back(x); S.insert(mp(min(x, v[l]), max(x, v[l]))); v.erase(v.begin() + l); } while (check()); } void DO(vector<int> &v) { if (v.empty()) return; vector<int> a, b; for (auto &i : v) { a.push_back(i); if (Query(a) < a.size()) { a.pop_back(); b.push_back(i); } } for (auto &i : b) BSH(a, i); DO(b); } void KILL(int id) { auto f = [&](int id, int a, int b) -> int { vector<int> v{id, a, b}; return Query(v); }; auto g = [&](int id, int a, int b, int c) -> int { if (f(id, a, b) == 1) return c; if (f(id, b, c) == 1) return a; return b; }; if (edge[id].size() == 1) return; int a = edge[id][0], b = edge[id][1], c = edge[id][2]; int d = g(id, a, b, c); if (id > d) swap(id, d); S.erase(mp(id, d)); } void Solve(int n) { int N = n * 2; vector<int> v; FOR(i, 1, N + 1) v.push_back(i); DO(v); FOR(i, 1, N + 1) KILL(i); for (auto i : S) Answer(i.fs, i.sc); }

Compilation message (stderr)

chameleon.cpp: In lambda function:
chameleon.cpp:18:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         bool f = (Query(v) != v.size());
      |                   ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void BSH(std::vector<int>, int)':
chameleon.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             (Query(w) != w.size() ? r : l) = mid;
      |              ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void DO(std::vector<int>&)':
chameleon.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if (Query(a) < a.size()) {
      |             ~~~~~~~~~^~~~~~~~~~
#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...