Submission #222955

# Submission time Handle Problem Language Result Execution time Memory
222955 2020-04-14T12:04:44 Z quocnguyen1012 Chameleon's Love (JOI20_chameleon) C++14
100 / 100
73 ms 512 KB
#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;

const int maxn = 1005;

int n;
vector<int> ind[4];
bool found[maxn];
vector<int> adj[maxn];

void Add(vector<int> vec, int u)
{
  int lo = 0, hi = vec.size() - 1, mid;
  while(lo <= hi){
    mid = (lo + hi) / 2;
    vector<int> tmp;
    for(int i = 0; i <= mid; ++i)
      tmp.eb(vec[i]);
    tmp.eb(u);
    if(Query(tmp) != tmp.size())
      hi = mid - 1;
    else
      lo = mid + 1;
  }
  adj[u].eb(vec[lo]); adj[vec[lo]].eb(u);
  vector<int> nxt;
  for(int i = lo + 1; i < vec.size(); ++i)
    nxt.eb(vec[i]);
  nxt.eb(u);
  if(Query(nxt) != nxt.size()){
    nxt.pop_back();
    Add(nxt, u);
  }
}

void Solve(int _N)
{
  n = _N;
  for(int i = 1; i <= 2 * n; ++i){
    vector<bool> kt(4, false);
    for(int j = 0; j < 4; ++j){
      vector<int> v(ind[j]); v.eb(i);
      if(Query(v) < v.size()){
        Add(ind[j], i);
      }
      else{
        kt[j] = true;
      }
    }
    for(int j = 0; j < 4; ++j){
      if(kt[j]){
        ind[j].eb(i);
        break;
      }
    }
  }
  auto check = [&](int a, int b) -> bool
  {
    vector<int> vi;
    for(int i = 1; i <= 2 * n; ++i){
      if(i != a && i != b)
        vi.eb(i);
    }
    return Query(vi) != n;
  };
  for(int i = 1; i <= 2 * n; ++i){
    if(found[i]) continue;
    for(int j : adj[i]){
      if(found[j]) continue;
      if(check(i, 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 'void Add(std::vector<int>, int)':
chameleon.cpp:96:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(Query(tmp) != tmp.size())
        ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:103:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = lo + 1; i < vec.size(); ++i)
                       ~~^~~~~~~~~~~~
chameleon.cpp:106:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(Query(nxt) != nxt.size()){
      ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:119:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if(Query(v) < v.size()){
          ~~~~~~~~~^~~~~~~~~~
# 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 44 ms 384 KB Output is correct
4 Correct 50 ms 384 KB Output is correct
5 Correct 48 ms 452 KB Output is correct
6 Correct 45 ms 512 KB Output is correct
7 Correct 43 ms 384 KB Output is correct
8 Correct 43 ms 384 KB Output is correct
9 Correct 45 ms 384 KB Output is correct
# 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 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
# 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 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 68 ms 384 KB Output is correct
4 Correct 69 ms 460 KB Output is correct
5 Correct 68 ms 384 KB Output is correct
6 Correct 69 ms 384 KB Output is correct
7 Correct 73 ms 504 KB Output is correct
8 Correct 69 ms 384 KB Output is correct
9 Correct 71 ms 384 KB Output is correct
# 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 44 ms 384 KB Output is correct
4 Correct 50 ms 384 KB Output is correct
5 Correct 48 ms 452 KB Output is correct
6 Correct 45 ms 512 KB Output is correct
7 Correct 43 ms 384 KB Output is correct
8 Correct 43 ms 384 KB Output is correct
9 Correct 45 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 68 ms 384 KB Output is correct
31 Correct 69 ms 460 KB Output is correct
32 Correct 68 ms 384 KB Output is correct
33 Correct 69 ms 384 KB Output is correct
34 Correct 73 ms 504 KB Output is correct
35 Correct 69 ms 384 KB Output is correct
36 Correct 71 ms 384 KB Output is correct
37 Correct 65 ms 384 KB Output is correct
38 Correct 43 ms 384 KB Output is correct
39 Correct 63 ms 384 KB Output is correct
40 Correct 62 ms 384 KB Output is correct
41 Correct 65 ms 384 KB Output is correct
42 Correct 43 ms 384 KB Output is correct
43 Correct 68 ms 384 KB Output is correct
44 Correct 63 ms 384 KB Output is correct
45 Correct 64 ms 504 KB Output is correct