제출 #28379

#제출 시각아이디문제언어결과실행 시간메모리
28379볼빨간 승관이 (#68)Bulb Game (FXCUP2_bulb)C++98
0 / 1
0 ms1128 KiB
#include <cstdio>
#include <cstring>
#include <algorithm>
bool haha[1005], check[1005];
int Num;
void Init(int N)
{
    memset(check, 0, sizeof(check));
    memset(haha, 0, sizeof(haha));
    Num = N;
}
int MakeTurn(int M)
{
    int flag = 0;
    int tcnt = 0, fcnt = 0, maxidx = 0, maxv = -987654321;
    for(int i = M; i < Num; ++i) {
        if(haha[i])
            tcnt++;
        else
            fcnt++;
        if(!check[i + 1] && maxv < fcnt - tcnt) {
            maxv = fcnt - tcnt;
            maxidx = i;
            flag = 1;
        }
    }
    tcnt = 0, fcnt = 0;
    for(int i = M - 1; i >= 1; --i) {
        if(haha[i])
            tcnt++;
        else
            fcnt++;
        if(!check[i] && maxv < fcnt - tcnt) {
            maxv = fcnt - tcnt;
            maxidx = i;
            flag = -1;
        }
    }
    if(flag > 0) {
        for(int i = M; i <= maxidx; ++i) {
            haha[i] = !haha[i];
        }
        check[maxidx + 1] = true;
        return maxidx + 1;
    }
    else {
        for(int i = maxidx; i < M; ++i) {
            haha[i] = !haha[i];
        }
        check[maxidx] = true;
        return maxidx;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...