#include "chameleon.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int Nn = 1000 + 5;
int vis[Nn];
vector<int> v[2], V[Nn];
void dfs(int u, int c) {
vis[u] = c;
v[c - 1].push_back(u);
for(int i = 0; i < V[u].size(); i++) {
if(!vis[V[u][i]]) dfs(V[u][i], 3 - c);
}
}
int query(int t, int l, int r, int i) {
vector<int> x; x.push_back(i);
for(int i = l; i <= r; i++) x.push_back(v[t][i]);
if(l > r) return 0;
return (Query(x) < r - l + 1 + 1);
}
void Solve(int N) {
for(int i = 2; i <= 2 * N; i++) {
for(int j = 1; j < i; j++) vis[j] = 0;
v[0].clear(); v[1].clear();
for(int j = 1; j < i; j++) {
if(!vis[j]) {
dfs(j, 2);
}
}
for(int t = 0; t < 2; t++) {
int lo = 0, hi = (int)v[t].size() - 1;
for(int c = 0; c < 3; c++) {
if(!query(t, lo, hi, i)) break;
int l = lo, r = hi, x = 0;
while(l <= r) {
int mid = (l + r) / 2;
if(!query(t, lo, mid, i)) l = mid + 1;
else r = mid - 1, x = mid;
}
V[i].push_back(v[t][x]);
V[v[t][x]].push_back(i);
lo = x + 1;
}
}
}
// 3nlogn + 4n + 6n
set<pair<int,int>> s;
for(int i = 1; i <= 2 * N; i++) {
if(V[i].size() == 3) {
for(int j = 0; j < 3; j++) {
if(V[i][j] < i) s.insert({V[i][j], i});
}
}
}
for(int i = 1; i <= 2 * N; i++) {
// cout << V[i].size() << endl;
if(V[i].size() == 1) {
if(V[i][0] < i) Answer(V[i][0], i);
continue;
}
if(Query({i, V[i][1], V[i][2]}) == 1) {
if(s.count({i, V[i][0]})) s.erase({i, V[i][0]});
else s.erase({V[i][0], i});
continue;
}
if(Query({i, V[i][0], V[i][2]}) == 1) {
if(s.count({i, V[i][1]})) s.erase({i, V[i][1]});
else s.erase({V[i][1], i});
continue;
}
if(s.count({i, V[i][2]})) s.erase({i, V[i][2]});
else s.erase({V[i][2], i});
}
while(s.size()) {
Answer((*--s.end()).first, (*--s.end()).second);
s.erase(--s.end());
}
}
Compilation message
chameleon.cpp: In function 'void dfs(int, int)':
chameleon.cpp:11:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i = 0; i < V[u].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
32 ms |
352 KB |
Output is correct |
4 |
Correct |
31 ms |
372 KB |
Output is correct |
5 |
Correct |
32 ms |
356 KB |
Output is correct |
6 |
Correct |
35 ms |
368 KB |
Output is correct |
7 |
Correct |
32 ms |
400 KB |
Output is correct |
8 |
Correct |
31 ms |
364 KB |
Output is correct |
9 |
Correct |
31 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
61 ms |
392 KB |
Output is correct |
4 |
Correct |
61 ms |
392 KB |
Output is correct |
5 |
Correct |
61 ms |
372 KB |
Output is correct |
6 |
Correct |
62 ms |
396 KB |
Output is correct |
7 |
Correct |
60 ms |
480 KB |
Output is correct |
8 |
Correct |
60 ms |
356 KB |
Output is correct |
9 |
Correct |
60 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
32 ms |
352 KB |
Output is correct |
4 |
Correct |
31 ms |
372 KB |
Output is correct |
5 |
Correct |
32 ms |
356 KB |
Output is correct |
6 |
Correct |
35 ms |
368 KB |
Output is correct |
7 |
Correct |
32 ms |
400 KB |
Output is correct |
8 |
Correct |
31 ms |
364 KB |
Output is correct |
9 |
Correct |
31 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
0 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
320 KB |
Output is correct |
16 |
Correct |
0 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
0 ms |
336 KB |
Output is correct |
29 |
Correct |
0 ms |
336 KB |
Output is correct |
30 |
Correct |
61 ms |
392 KB |
Output is correct |
31 |
Correct |
61 ms |
392 KB |
Output is correct |
32 |
Correct |
61 ms |
372 KB |
Output is correct |
33 |
Correct |
62 ms |
396 KB |
Output is correct |
34 |
Correct |
60 ms |
480 KB |
Output is correct |
35 |
Correct |
60 ms |
356 KB |
Output is correct |
36 |
Correct |
60 ms |
396 KB |
Output is correct |
37 |
Correct |
62 ms |
392 KB |
Output is correct |
38 |
Correct |
31 ms |
352 KB |
Output is correct |
39 |
Correct |
61 ms |
372 KB |
Output is correct |
40 |
Correct |
63 ms |
596 KB |
Output is correct |
41 |
Correct |
64 ms |
464 KB |
Output is correct |
42 |
Correct |
31 ms |
336 KB |
Output is correct |
43 |
Correct |
61 ms |
388 KB |
Output is correct |
44 |
Correct |
62 ms |
368 KB |
Output is correct |
45 |
Correct |
63 ms |
372 KB |
Output is correct |