Submission #1267631

#TimeUsernameProblemLanguageResultExecution timeMemory
1267631ti24dung_nt동굴 (IOI13_cave)C++20
Compilation error
0 ms0 KiB
#include "cave.h"

void exploreCave(int n)
{
    int s[n], d[n], swch[n], stateOpen[n];

    for(int curDoor = 0; curDoor < n; ++curDoor)
    {
        for(int i = 0; i < n; ++i) s[i] = 0;
        for(int prevDoor = 0; prevDoor < curDoor; ++prevDoor) s[swch[prevDoor]] = stateOpen[prevDoor];
        int losestDoor = tryCombination(s);

        if(losestDoor == curDoor) stateOpen[curDoor] = 1;
        else stateOpen[curDoor] = 0;

        int l = 0, r = n - 1;
        while(l < r)
        {
            int mid = (l + r) / 2;

            for(int i = 0; i < n; ++i)
            {
                if(i <= mid) s[i] = 0;
                else s[i] = 1;
            }
            for(int j = 0; j < i; ++j) s[swch[j]] = stateOpen[j];

            losestDoor = tryCombination(s);

            if(losestDoor == curDoor)
            {
                if(stateOpen[curDoor] == 0) l = mid + 1;
                else r = mid;
            }
            else
            {
                if(stateOpen[curDoor] == 0) r = mid;
                else l = mid;
            }
        }

        d[l] = curDoor;
        swch[curDoor] = l;
    }

    answer(s, d);
}

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:26:32: error: 'i' was not declared in this scope
   26 |             for(int j = 0; j < i; ++j) s[swch[j]] = stateOpen[j];
      |                                ^