Submission #950375

# Submission time Handle Problem Language Result Execution time Memory
950375 2024-03-20T08:59:52 Z kilkuwu Cave (IOI13_cave) C++17
0 / 100
139 ms 524 KB
#ifdef LOCAL
int tryCombination(int S[]);
void answer(int S[], int D[]);
void exploreCave(int N);
#else 
#include "cave.h"
#endif

#ifdef LOCAL
#include "template\debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif

#include <bits/stdc++.h>

constexpr int mxN = 5000;
int s[mxN], d[mxN], ord[mxN];
int _n;

int ask_switched(int p) {
  for (int i = p; i < _n; i++) {
    s[ord[i]] ^= 1;
  }
  int res = tryCombination(s); 
  for (int i = p; i < _n; i++) {
    s[ord[i]] ^= 1;
  }
  if (res == -1) res = _n;
  return res;
}

void exploreCave(int N) {
  _n = N;
  int opened = tryCombination(s);
  for (int i = 0; i < N; i++) ord[i] = i;
  for (int i = 0; i < N; i++) {
    int is_open = opened > i; // opened >= i anyway
    if (is_open) {
      // find first switch to make it close
      int lb = i, rb = N - 1;
      while (lb < rb) {
        int mid = (lb + rb + 1) / 2;

        if (ask_switched(mid) <= i) {
          lb = mid;
        } else {
          rb = mid - 1;
        }
      }

      d[ord[lb]] = i;
      std::swap(ord[lb], ord[i]);
    } else {
      int lb = i, rb = N - 1;
      while (lb < rb) {
        int mid = (lb + rb + 1) / 2;

        if (ask_switched(mid) > i) {
          lb = mid;
        } else {
          rb = mid - 1;
        }
      }

      d[ord[lb]] = i;
      std::swap(ord[lb], ord[i]);
      
      // we gotta swap this 

      s[ord[i]] ^= 1;
    }
  }

  answer(s, d);
}

#ifdef LOCAL
#include <stdio.h>
#include <stdlib.h>

#define MAX_N 5000
#define MAX_CALLS 70000

#define fail(s, x...) do { \
  fprintf(stderr, s "\n", ## x); \
  exit(1); \
} while(0)

/* Symbol obfuscation */
#define N koala
#define realS kangaroo
#define realD possum
#define inv platypus
#define num_calls echidna

static int N;
static int realS[MAX_N];
static int realD[MAX_N];
static int inv[MAX_N];
static int num_calls;

void answer(int S[], int D[]) {
  int i;
  int correct = 1;
  for (i = 0; i < N; ++i)
    if (S[i] != realS[i] || D[i] != realD[i]) {
      correct = 0;
      break;
    }

  if (correct)
    printf("CORRECT\n");
  else
    printf("INCORRECT\n");

  for (i = 0; i < N; ++i) {
    if (i > 0)
      printf(" ");
    printf("%d", S[i]);
  }
  printf("\n");

  for (i = 0; i < N; ++i) {
    if (i > 0)
      printf(" ");
    printf("%d", D[i]);
  }
  printf("\n");

  exit(0);
}

int tryCombination(int S[]) {
  int i;

  if (num_calls >= MAX_CALLS) {
    printf("INCORRECT\nToo many calls to tryCombination().\n");
    exit(0);
  }
  ++num_calls;

  for (i = 0; i < N; ++i)
    if (S[inv[i]] != realS[inv[i]])
      return i;
  return -1;
}

int init() {
  int i, res;

  FILE *f = fopen("cave.in", "r");
  if (!f)
    fail("Failed to open input file.");

  res = fscanf(f, "%d", &N);

  for (i = 0; i < N; ++i) {
    res = fscanf(f, "%d", &realS[i]);
  }
  for (i = 0; i < N; ++i) {
    res = fscanf(f, "%d", &realD[i]);
    inv[realD[i]] = i;
  }

  num_calls = 0;
  return N;
}

int main() {
  int n;
  n = init();
  exploreCave(n);
  printf("incorrect\nyour solution did not call answer().\n");
  return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 524 KB Answer is wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 344 KB Answer is wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Answer is wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Answer is wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 524 KB Answer is wrong
2 Halted 0 ms 0 KB -