답안 #415265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
415265 2021-05-31T18:56:29 Z Mamnoon_Siam 카멜레온의 사랑 (JOI20_chameleon) C++17
4 / 100
47 ms 308 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second

namespace {

}  // namespace

void Solve(int N) {
  vi done(2*N + 1);
  function<vi(int, int)> grab = [&done](int l, int r) {
    vi ret;
    for(int i = l; i <= r; ++i) {
      if(!done[i]) ret.emplace_back(i);
    }
    return ret;
  };
  for(int it = 0; it < N; ++it) {
    int l = -1, r = -1;
    {
      int lo = 1, hi = 2*N;
      while(lo <= hi) {
        int mid = (lo + hi) >> 1;
        vi p = grab(1, mid);
        if(!sz(p) or Query(p) == sz(p)) {
          lo = mid+1;
        } else {
          r = mid;
          hi = mid-1;
        }
      }
    }
    {
      int lo = 1, hi = 2*N;
      while(lo <= hi) {
        int mid = (lo + hi) >> 1;
        vi p = grab(mid, r);
        if(!sz(p) or Query(p) == sz(p)) {
          hi = mid-1;
        } else {
          l = mid;
          lo = mid+1;
        }
      }
    }
    Answer(l, r);
    done[l] = done[r] = 1;
  }
}

#ifdef LOCAL
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) {
  ++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);
}

int main() {
  freopen("sample-02-in.txt", "r", stdin);
  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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 47 ms 284 KB Output is correct
4 Correct 43 ms 200 KB Output is correct
5 Correct 45 ms 200 KB Output is correct
6 Correct 45 ms 200 KB Output is correct
7 Correct 44 ms 288 KB Output is correct
8 Correct 45 ms 200 KB Output is correct
9 Correct 46 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Incorrect 1 ms 200 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Incorrect 1 ms 200 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Incorrect 1 ms 200 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 47 ms 284 KB Output is correct
4 Correct 43 ms 200 KB Output is correct
5 Correct 45 ms 200 KB Output is correct
6 Correct 45 ms 200 KB Output is correct
7 Correct 44 ms 288 KB Output is correct
8 Correct 45 ms 200 KB Output is correct
9 Correct 46 ms 308 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Incorrect 1 ms 200 KB Wrong Answer [6]
12 Halted 0 ms 0 KB -