Submission #1025544

#TimeUsernameProblemLanguageResultExecution timeMemory
1025544dozerCave (IOI13_cave)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define st first
#define nd second
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define LL node * 2
#define RR node * 2 + 1
#define mid (l + r) / 2
#define ll long long
#define MAXN 200005
#define LOGN 12

#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");

    cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\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;
    freopen("output.txt", "w", stdout);
    FILE *f = fopen("input.txt", "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;
}



void exploreCave(int N) {
    int done[N], curr[N];
    for (int i = 0; i < N; i++)
        done[i] = -1, curr[i] = 0;


    auto question = [&](int x, int val){
        int tmpx = x;
        int lst = -1;
        for (int i = 0; i < N; i++){
            if (x > 0 && done[i] == -1) curr[i] = val, x--, lst = i;
            else if (done[i] == -1) curr[i] = 1 - val;
        }
        int res = tryCombination(curr);
        return res;
    };



    for (int i = 0; i < N; i++){
        int val = 0;
        if (question(0, 1) >= i + 1 || question(0, 1) == -1){
            val = 1;
        }

        int pos = 0;
        for (int j = LOGN; j >= 0; j--){
            int tmp = pos + (1<<j);
            int t = question(tmp, val);
           // cout<<i<<sp<<val<<sp<<tmp<<sp<<t<<endl;
            if (t >= i + 1 || t == -1) pos = tmp;
        }

        pos++;
        int lst = 0;
        for (int i = 0; i < N; i++){
            if (done[i] == -1 && pos > 0) lst = i, pos--;
        }

        done[lst] = i;
        curr[lst] = 1 - val;
    }


    answer(curr, done);
}

Compilation message (stderr)

cave.cpp: In function 'int init()':
cave.cpp:88:12: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   88 |     int i, res;
      |            ^~~
cave.cpp: In lambda function:
cave.cpp:117:13: warning: unused variable 'tmpx' [-Wunused-variable]
  117 |         int tmpx = x;
      |             ^~~~
cave.cpp:118:13: warning: variable 'lst' set but not used [-Wunused-but-set-variable]
  118 |         int lst = -1;
      |             ^~~
cave.cpp: In function 'int init()':
cave.cpp:89:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cctYa2Za.o: in function `answer':
cave.cpp:(.text+0x0): multiple definition of `answer'; /tmp/ccIiGhob.o:grader.c:(.text+0x0): first defined here
/usr/bin/ld: /tmp/cctYa2Za.o: in function `tryCombination':
cave.cpp:(.text+0x190): multiple definition of `tryCombination'; /tmp/ccIiGhob.o:grader.c:(.text+0x80): first defined here
/usr/bin/ld: /tmp/cctYa2Za.o: in function `init()':
cave.cpp:(.text+0x220): multiple definition of `init()'; /tmp/ccIiGhob.o:grader.c:(.text+0x110): first defined here
collect2: error: ld returned 1 exit status