답안 #28382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28382 2017-07-16T05:07:47 Z 볼빨간 승관이(#1152, sys7961, deneb2016, hyorothy) Bulb Game (FXCUP2_bulb) C++
1 / 1
3 ms 1128 KB
#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;
    check[M] = true;
    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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1128 KB Output is correct
2 Correct 0 ms 1128 KB Output is correct
3 Correct 0 ms 1128 KB Output is correct
4 Correct 0 ms 1128 KB Output is correct
5 Correct 0 ms 1128 KB Output is correct
6 Correct 0 ms 1128 KB Output is correct
7 Correct 0 ms 1128 KB Output is correct
8 Correct 0 ms 1128 KB Output is correct
9 Correct 0 ms 1128 KB Output is correct
10 Correct 0 ms 1128 KB Output is correct
11 Correct 0 ms 1128 KB Output is correct
12 Correct 0 ms 1128 KB Output is correct
13 Correct 0 ms 1128 KB Output is correct
14 Correct 0 ms 1128 KB Output is correct
15 Correct 0 ms 1128 KB Output is correct
16 Correct 0 ms 1128 KB Output is correct
17 Correct 0 ms 1128 KB Output is correct
18 Correct 0 ms 1128 KB Output is correct
19 Correct 0 ms 1128 KB Output is correct
20 Correct 0 ms 1128 KB Output is correct
21 Correct 3 ms 1128 KB Output is correct
22 Correct 0 ms 1128 KB Output is correct