제출 #16207

#제출 시각아이디문제언어결과실행 시간메모리
16207mindol동굴 (IOI13_cave)C++98
100 / 100
1061 ms608 KiB
#include "cave.h"
#include<cstdio>
int temp[5001]; // 시도할 배열
bool check[5001]; // check[i] : i번째 스위치를 알아냈는지
int ans[5001]; // ans[i] : i번째 스위치의 답(i번째 스위치에 연결된 문을 열리게 하는 스위치의 답)
int connected[5001]; // connected[i]  :i번째 스위치와 연결된 문
void exploreCave(int N) {
    for(int i=0;i<N;i++) // i번째 문과 연결된 스위치를 찾을 것임.
    {
        for(int j=0;j<N;j++)
        {
            if(check[j]) temp[j]=ans[j];
            else temp[j]=0;
        } // 일단 스위치를 다 올려본다.

        int res=tryCombination(temp);
        if(res!=i)
        {
            for(int j=0;j<N;j++)
            {
                if(check[j]) temp[j]=ans[j];
                else temp[j]=1;
            } // 일단 스위치를 다 내려본다.
        }

        // 이제 i번째 문이 막혀있음

        int s=0,e=N-1;
        while(s<e)
        {
            int mid=(s+e)/2;
            for(int j=0;j<=mid;j++)
            {
                if(check[j]) temp[j]=ans[j];
                else temp[j]=!temp[j];
            } // 0~mid번째 까지를 반전시켜본다.

            int res=tryCombination(temp);
            if(res==i) // 그래도 i번째 문이 막혀있다면
            {
                // i번째 문에 연결된 문은 mid+1~e까지에 있다.
                s=mid+1;
            }
            else // i번째 문이 열렸다면
            {
                // i번째 문에 연결된 문은 s~mid까지에 있다.
                e=mid;
                for(int j=0;j<=mid;j++)
                {
                    if(check[j]) temp[j]=ans[j];
                    else temp[j]=!temp[j];
                } // 다시 원래대로
            }
        }
        check[s]=true;
        ans[s]=!temp[s];
        connected[s]=i;
    }
    answer(ans,connected);
}
#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...