This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
static vector<int> g[MAXN + 1];
static vector<int> side[2];
static bool vis[MAXN + 1];
void dfs(int nod, int col) {
if(vis[nod]) return ;
vis[nod] = 1;
side[col].push_back(nod);
for(auto it : g[nod]) {
dfs(it, col ^ 1);
}
}
void Solve(int n) {
vector<set<int>> all(2 * n + 1);
for(int i = 1; i <= 2 * n; i++) {
for(int t = 0; t < 2; t++) {
int x = -1, sz = side[t].size();
while(x < sz) {
int y = x;
for(int step = 1 << 9; step; step >>= 1) {
if(y + step < sz) {
vector<int> cur;
cur.push_back(i);
for(int j = x + 1; j <= y + step; j++) {
cur.push_back(side[t][j]);
}
if(Query(cur) == cur.size()) {
y += step;
}
}
}
y++;
if(y < sz) {
all[i].insert(side[t][y]);
all[side[t][y]].insert(i);
g[i].push_back(side[t][y]);
g[side[t][y]].push_back(i);
}
x = y;
}
side[t].clear();
}
fill(vis, vis + i + 1, 0);
for(int j = 1; j <= i; j++) {
dfs(j, 0);
}
}
for(int i = 1; i <= 2 * n; i++) {
g[i].clear();
}
for(int i = 1; i <= 2 * n; i++) {
vector<int> cur;
for(auto it : all[i]) {
cur.push_back(it);
}
int j;
if(cur.size() == 3) {
if(Query({i, cur[0], cur[1]}) == 1) {
j = cur[2];
}
else if(Query({i, cur[1], cur[2]}) == 1) {
j = cur[0];
}
else {
j = cur[1];
}
g[i].push_back(j);
g[j].push_back(i);
}
}
for(int i = 1; i <= 2 * n; i++) {
for(auto it : g[i]) {
if(all[i].count(it)) {
all[i].erase(it);
}
}
assert(all[i].size() == 1);
if(*all[i].begin() > i) {
Answer(i, *all[i].begin());
}
}
}
Compilation message (stderr)
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:35:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(cur) == cur.size()) {
~~~~~~~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |