Submission #31081

# Submission time Handle Problem Language Result Execution time Memory
31081 2017-08-06T16:55:15 Z WhipppedCream Cave (IOI13_cave) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
bool solved[5005];
int sol[5005];
int connect[5005];
int arr[5005];
int tmp[5005];
vi cand;
void exploreCave(int n)
{
    for(int i = 0; i< n; i++) cand.pb(i);
    for(int it = 0; it< n-1; it++)
    {
        //printf("-----iteration %d\n", it);
        for(int i = 0; i< n; i++) if(solved[i]) arr[i] = sol[i];
        for(int i = 0; i< (int) cand.size(); i++) arr[cand[i]] = 0;
        int last = tryCombination(arr);
        if(last == -1) last = 1e9;
        int L = 0, R = cand.size()-1;
        memset(tmp, 0, sizeof tmp);
        while(L< R)
        {
            //printf("L = %d and R = %d\n", L, R);
            int mid = (L+R)/2;
            for(int i = 0; i< n; i++) if(solved[i]) arr[i] = sol[i];
            for(int i = mid+1; i<= R; i++) if(!solved[cand[i]]) arr[cand[i]] = 1-arr[cand[i]];
            int x = tryCombination(arr);
            if(x == -1) x = 1e9;
            if(x< last)
            {
                L = mid+1;
                last = x;
                if(L == R) sol[cand[L]] = 1-arr[cand[L]];
            }
            else if(x> last)
            {
                L = mid+1;
                if(L == R) sol[cand[L]] = arr[cand[L]];
                for(int i = mid+1; i<= R; i++) if(!solved[cand[i]]) arr[cand[i]] = 1-arr[cand[i]];
            }
            else
            {
                int trex = R;
                R = mid;
                if(L == R) sol[cand[L]]= 1-arr[cand[L]];
                for(int i = mid+1; i<= trex; i++) if(!solved[cand[i]]) arr[cand[i]] = 1-arr[cand[i]];
            }
        }
        connect[cand[L]] = last;
        solved[cand[L]] = 1;
        //printf("connect %d to %d\n", cand[L], last);
        //printf("position for %d is %d\n", cand[L], sol[cand[L]]);
        cand.erase(cand.begin()+L);
    }
    int pos = cand[0];
    //printf("pos is %d\n", pos);
    memset(arr, 0, sizeof arr);
    for(int i = 0; i< n; i++) if(solved[i]) arr[i] = sol[i];
    int x = tryCombination(arr);
    int y;
    if(x == -1)
    {
        arr[pos] = 1-arr[pos];
        y = tryCombination(arr);
        sol[pos] = 1-arr[pos];
    }
    else
    {
        y = x;
        sol[pos] = 1-arr[pos];
    }
    connect[pos] = y;
    answer(sol, connect);
}

Compilation message

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:19:20: error: 'tryCombination' was not declared in this scope
         int last = tryCombination(arr);
                    ^~~~~~~~~~~~~~
cave.cpp:61:13: error: 'tryCombination' was not declared in this scope
     int x = tryCombination(arr);
             ^~~~~~~~~~~~~~
cave.cpp:75:5: error: 'answer' was not declared in this scope
     answer(sol, connect);
     ^~~~~~
cave.cpp:75:5: note: suggested alternative: 'assert'
     answer(sol, connect);
     ^~~~~~
     assert