Submission #1313381

#TimeUsernameProblemLanguageResultExecution timeMemory
1313381shirokitoCave (IOI13_cave)C++20
Compilation error
0 ms0 KiB
#ifndef LOCAL
    #include "cave.h"
#endif

#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

using ll = long long;

const int N = 5000 + 24;

#ifdef LOCAL
int n, real_s[N], real_d[N];

int tryCombination(vector<int> S) {

    for (int i = 0; i < n; i++) {
        cout << S[i] << ' ';
    }
    cout << endl;

    vector<int> state(n);


    for (int i = 0; i < n; i++) {
        int j = real_d[i];
        state[j] = (S[i] == real_s[i]);

    }
        
    cout << "STATE: ";
    for (int j = 0; j < n; j++) cout << state[j] << ' '; cout << endl;

    for (int i = 0; i < n; i++) {
        if (!state[i]) return cout << i << endl, i;
    }

    return cout << -1 << endl, -1;
}

void answer(vector<int> S, vector<int> D) {
    bool valid = 1;

    for (int i = 0; i < n; i++) {
        if (S[i] != real_s[i]) {
            valid = 0;
            break;
        }
    }

    for (int i = 0; i < n; i++) {
        if (D[i] != real_d[i]) {
            valid = 0;
            break;
        }
    }

    if (!valid) {
        cout << "WRONG ANSWER" << endl;
        for (int x: S) cout << x << ' '; cout << endl; 
        for (int x: D) cout << x << ' '; cout << endl; 
    }
    else {
        cout << "CORRECT" << endl;
    }
}

#else

int tryCombination(vector<int> S);
void answer(vector<int> S, vector<int> D);

#endif

void exploreCave(int N) {
    int n = N;

    vector<int> state(n, 0), can(n, 1);

    for (int i = 0; i < n; i++) {
        int k = tryCombination(state);
        int m = tryCombination(can);

        if (m != -1 && m < k) {
            int pos = -1;

            for (int l = 0, r = n - 1; l <= r; ) {
                int mid = (l + r) >> 1;

                vector<int> new_state = state;

                for (int i = 0; i <= mid; i++) {
                    if (can[i]) new_state[i] = 1;
                }

                int jury_ans = tryCombination(new_state);

                if (jury_ans != -1 &&  jury_ans < k) {
                    pos = mid;
                    r = mid - 1;
                }
                else l = mid + 1;
            }

            if (pos != -1) {
                can[pos] = 0;
                // cout << "POS = " << pos << "\n";
            }
        }

        else {
            int pos = -1;
        
            for (int l = 0, r = n - 1; l <= r; ) {
                int mid = (l + r) >> 1;

                vector<int> new_state = state;

                for (int i = 0; i <= mid; i++) {
                    if (can[i]) new_state[i] = 1;
                }

                int jury_ans = tryCombination(new_state);

                if (jury_ans == -1 || jury_ans > k) {
                    pos = mid;
                    r = mid - 1;
                }
                else l = mid + 1;  
            }

            if (pos != -1) {
                // cout << "POS = " << pos << "\n";
                state[pos] = 1;
            }
        }
    }

    vector<int> d(n);

    for (int i = 0; i < n; i++) {
        vector<int> new_state = state;
        new_state[i] ^= 1;
        d[i] = tryCombination(new_state);
    }

    return answer(state, d);
}

#ifdef LOCAL 
void solve() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> real_s[i];
    }

    for (int i = 0; i < n; i++) {
        cin >> real_d[i];
    }

    exploreCave(n);
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);

    int T = 1; // cin >> T;
    while (T--) {
        solve();
    }
}
#endif

Compilation message (stderr)

/usr/bin/ld: /tmp/ccFPXk31.o: in function `exploreCave':
cave.cpp:(.text+0x16e): undefined reference to `tryCombination(std::vector<int, std::allocator<int> >)'
/usr/bin/ld: cave.cpp:(.text+0x1ed): undefined reference to `tryCombination(std::vector<int, std::allocator<int> >)'
/usr/bin/ld: cave.cpp:(.text+0x32d): undefined reference to `tryCombination(std::vector<int, std::allocator<int> >)'
/usr/bin/ld: cave.cpp:(.text+0x4b5): undefined reference to `tryCombination(std::vector<int, std::allocator<int> >)'
/usr/bin/ld: cave.cpp:(.text+0x793): undefined reference to `tryCombination(std::vector<int, std::allocator<int> >)'
/usr/bin/ld: cave.cpp:(.text+0x8b3): undefined reference to `answer(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status