Submission #68782

# Submission time Handle Problem Language Result Execution time Memory
68782 2018-08-18T11:17:04 Z someone_aa Cave (IOI13_cave) C++17
0 / 100
260 ms 632 KB
#include <bits/stdc++.h>
#include "cave.h"

using namespace std;

const int maxn = 5100;
int open[maxn], sw[maxn], n;
int f[maxn], bq;

int curr[maxn];

bool valid(int l, int r) {
    bool valid = false;
    for(int i=l;i<=r;i++) {
        if(f[i] == -1) valid = true;
    }
    return valid;
}

bool validq(int ind, int l, int r) {
    for(int i=l;i<=r;i++) {
        if(f[i] == -1) {
            curr[i] = 1;
        }
    }
    int ans = tryCombination(curr);

    for(int i=l;i<=r;i++) {
        if(f[i] == -1) {
            curr[i] = 0;
        }
    }

    if((bq <= ind && bq!=-1)&& (ans == ind + 1 || ans == -1)) return true;// otvorile su se vrata ss index ind
    else if((bq > ind || bq==-1) && ans <= ind) return true; // zatvorile su se tija vrata
    else return false;
}

void setind(int ind, int x) {
    curr[ind] = 1;
    int ans = tryCombination(curr);

    //cout<<"Connecting door: "<<x<<" with switch: "<<ind<<"\n";

    if(ans > x || ans == -1) {
        f[ind] = 1;
        curr[ind] = 1;
    }
    else if(ans == x) {
        f[ind] = 0;
        curr[ind] = 0;
    }
    /*cout<<"Connection done:\n";
    for(int i=0;i<n;i++) {
        cout<<curr[i]<<" ";
    } cout<<"\n";*/
}

void solve(int ind, int l=0, int r=n) {
    int mid = (l+r)/2;
    //cout<<ind<<": "<<l<<" "<<r<<"\n";
    if(l==r) {
        sw[l] = ind;
        setind(l, ind);
    }
    else {
        if(valid(l, mid)) {
            if(validq(ind, l, mid)) {
                solve(ind, l, mid);
            }
            else {
                solve(ind, mid+1, r);
            }
        }
        else {
            solve(ind, mid+1, r);
        }
    }
}

void exploreCave(int N) {
    n = N;
    memset(f,-1,sizeof(f));
    for(int i=0;i<N;i++) {
        bq = tryCombination(curr);
        /*cout<<"Before start:\n";
        for(int i=0;i<N;i++) {
            cout<<curr[i]<<" ";
        }cout<<"\n";
        for(int i=0;i<N;i++) {
            cout<<f[i]<<" ";
        } cout<<"\n";*/
        solve(i, 0, N-1);
    }
    answer(curr, sw);
}
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 500 KB Answer is wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 157 ms 516 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 260 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 249 ms 632 KB Output is correct
7 Incorrect 249 ms 516 KB too much calls on tryCombination()
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Incorrect 5 ms 384 KB Answer is wrong
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Incorrect 5 ms 384 KB Answer is wrong
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 500 KB Answer is wrong
2 Halted 0 ms 0 KB -