Submission #781059

#TimeUsernameProblemLanguageResultExecution timeMemory
781059caganyanmazCave (IOI13_cave)C++17
100 / 100
562 ms516 KiB
#include <bits/stdc++.h>
using namespace std;
#include "cave.h"

constexpr static int MXSIZE = 5000;
int n;
int s[MXSIZE], d[MXSIZE]; // Result
int c[MXSIZE]; // For queries

bool is_visibly_open(int i, int result)
{
        return result > i || result == -1;
}

void exploreCave(int N)
{
        n = N;
        for (int i = 0; i < n; i++)
                d[i] = -1;
        for (int i = 0; i < n; i++)
        {
                for (int j = 0; j < n; j++)
                        c[j] = (d[j] == -1) ? 0 : s[j];
                int correct = 1;
                if (is_visibly_open(i, tryCombination(c)))
                        correct = 0;
                int l = -1, r = n;
                while (r - l > 1)
                {
                        int m = l+r>>1;
                        for (int j = 0; j <= m; j++)
                                c[j] = (d[j] == -1) ? correct : s[j];
                        for (int j = m+1; j < n; j++)
                                c[j] = (d[j] == -1) ? (1 - correct) : s[j];
                        if (is_visibly_open(i, tryCombination(c)))
                                r = m;
                        else
                                l = m;
                }
                d[r] = i;
                s[r] = correct;
        }
        answer(s, d);
}

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:30:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |                         int m = l+r>>1;
      |                                 ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...