#ifndef LOCAL
#include "chameleon.h"
#endif // LOCAL
#ifdef LOCAL
#include<bits/stdc++.h>
using namespace std;
namespace {
using std::exit;
using std::fprintf;
using std::printf;
using std::scanf;
constexpr int Q_MAX = 20'000;
constexpr int N_MAX = 500;
int N;
int Y[N_MAX * 2 + 1], C[N_MAX * 2 + 1], L[N_MAX * 2 + 1];
int query_count = 0;
int answer_count = 0;
bool finishes[N_MAX * 2 + 1];
void WrongAnswer(int code) {
printf("Wrong Answer [%d]\n", code);
exit(0);
}
} // namespace
int Query(const std::vector<int> &p) {
if (++query_count > Q_MAX) WrongAnswer(3);
bool presents[N_MAX * 2 + 1];
for (int i = 1; i <= N * 2; ++i) presents[i] = false;
for (const int k : p) {
if (k <= 0 || k > N * 2) WrongAnswer(1);
if (presents[k]) WrongAnswer(2);
presents[k] = true;
}
bool colors[N_MAX + 1];
for (int j = 1; j <= N; ++j) colors[j] = false;
int color_count = 0;
for (int i = 1; i <= N * 2; ++i) {
if (!presents[i]) continue;
const int color = presents[L[i]] ? C[L[i]] : C[i];
if (!colors[color]) {
++color_count;
colors[color] = true;
}
}
return color_count;
}
void Answer(int a, int b) {
cerr << a << ' ' << b << '\n';
++answer_count;
if (a <= 0 || a > N * 2) WrongAnswer(4);
if (b <= 0 || b > N * 2) WrongAnswer(4);
if (finishes[a]) WrongAnswer(5);
finishes[a] = true;
if (finishes[b]) WrongAnswer(5);
finishes[b] = true;
if (C[a] != C[b]) WrongAnswer(6);
}
#endif //LOCAL
/*#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
void Solve(int N)
{
}
*/
#include <bits/stdc++.h>
using namespace std;
int n;
bool sex[1005];
vector <int> v[1005];
vector <int> Left, Right;
vector <int> cand[1005];
bool isCandidate(int x, int y, vector <int> v, int val){
vector <int> q;
if(val != -1) q.push_back(val);
for(int i = x; i <= y ; ++i) q.push_back(v[i]);
return Query(q) - q.size();
}
bool find_candidates(int i, vector <int> v){
if(!v.empty()){
while(isCandidate(0, v.size() - 1, v, i)){
if(v.size() == 1){
cand[i].push_back(v[0]);
cand[v[0]].push_back(i);
v.pop_back();
break ;
}
int st = 1, dr = v.size();
while(st <= dr){
int mij = (st + dr) / 2;
if(isCandidate(st - 1, mij - 1, v, i)) dr = mij - 1;
else st = mij + 1;
}
cand[i].push_back(v[st - 1]);
cand[v[st - 1]].push_back(i);
swap(v[st - 1], v[v.size() - 1]);
v.pop_back();
if(v.empty() || cand[i].size() == 3) break ;
}
}
}
bool viz[1005];
void color(int nod){
viz[nod] = 1;
for(auto it : cand[nod]){
if(viz[it]) continue ;
sex[it] = 1 - sex[nod];
color(it);
}
}
bool match[1005][1005];
bool found[1005];
bool check(int a, int b)
{
vector<int> v;
for(int i = 1; i <= 2 * n; ++i){
if(i != a && i != b){
v.push_back(i);
}
}
return Query(v) == n - 1;
}
void Solve(int N){
n = N;
for(int i = 2; i <= 2 * n ; ++i){
for(int j = 1; j < i ; ++j) viz[j] = 0;
sex[i - 1] = 0;
color(i - 1);
///we find all the chameleons on the left
Left.clear();
for(int j = 1; j < i ; ++j)
if(sex[j] == 0 && cand[j].size() < 3) Left.push_back(j);
find_candidates(i, Left);
if(cand[i].size() == 3) continue ;
///we find all the chameleons on the right
Right.clear();
for(int j = 1; j < i ; ++j)
if(sex[j] == 1 && cand[j].size() < 3) Right.push_back(j);
find_candidates(i, Right);
}
for(int i = 1; i <= 2 * n; ++i){
if(found[i]) continue;
for(int j : cand[i]){
if(found[i] == found[j]){
found[i] = found[j] = 1;
Answer(i, j);
break;
}
}
}
}
#ifdef LOCAL
int main() {
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
if (scanf("%d", &N) != 1) {
fprintf(stderr, "Error while reading input.\n");
exit(1);
}
for (int i = 1; i <= N * 2; ++i) {
if (scanf("%d", &Y[i]) != 1) {
fprintf(stderr, "Error while reading input.\n");
exit(1);
}
}
for (int i = 1; i <= N * 2; ++i) {
if (scanf("%d", &C[i]) != 1) {
fprintf(stderr, "Error while reading input.\n");
exit(1);
}
}
for (int i = 1; i <= N * 2; ++i) {
if (scanf("%d", &L[i]) != 1) {
fprintf(stderr, "Error while reading input.\n");
exit(1);
}
}
for (int i = 1; i <= N * 2; ++i) finishes[i] = false;
Solve(N);
if (answer_count != N) WrongAnswer(7);
printf("Accepted: %d\n", query_count);
return 0;
}
#endif // LOCAL
Compilation message
chameleon.cpp: In function 'bool find_candidates(int, std::vector<int>)':
chameleon.cpp:131:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
33 ms |
384 KB |
Output is correct |
4 |
Correct |
38 ms |
384 KB |
Output is correct |
5 |
Correct |
38 ms |
384 KB |
Output is correct |
6 |
Correct |
36 ms |
512 KB |
Output is correct |
7 |
Correct |
35 ms |
504 KB |
Output is correct |
8 |
Correct |
34 ms |
384 KB |
Output is correct |
9 |
Correct |
35 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
33 ms |
384 KB |
Output is correct |
4 |
Correct |
38 ms |
384 KB |
Output is correct |
5 |
Correct |
38 ms |
384 KB |
Output is correct |
6 |
Correct |
36 ms |
512 KB |
Output is correct |
7 |
Correct |
35 ms |
504 KB |
Output is correct |
8 |
Correct |
34 ms |
384 KB |
Output is correct |
9 |
Correct |
35 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [6] |
12 |
Halted |
0 ms |
0 KB |
- |