목차

Coloring 2: Electric Boogaloo

ps
링크acmicpc.net/…
출처BOJ
문제 번호32381
문제명Coloring 2: Electric Boogaloo
레벨골드 2
분류

애드 혹

시간복잡도O(n)
인풋사이즈n<=300,000
사용한 언어Python 3.11
제출기록70976KB / 252ms
최고기록252ms
해결날짜2024/10/15

풀이

코드

"""Solution code for "BOJ 32381. Coloring 2: Electric Boogaloo".

- Problem link: https://www.acmicpc.net/problem/32381
- Solution link: http://www.teferi.net/ps/problems/boj/32381
"""


def main():
    N, Q = [int(x) for x in input().split()]  # pylint: disable=unused-variable
    black_counts = [int(x) for x in input().split()]

    flipped_col_count = flipped_row_count = 0
    black_count_cur = 0
    answer = []
    for b in black_counts:
        black_count_prev, black_count_cur = black_count_cur, b
        inc = black_count_cur - black_count_prev
        if inc == N - (flipped_col_count * 2) and flipped_row_count < N:
            answer.append(f'R {flipped_row_count + 1}')
            flipped_row_count += 1
        elif inc == -(N - (flipped_col_count * 2)) and flipped_row_count > 0:
            answer.append(f'R {flipped_row_count}')
            flipped_row_count -= 1
        elif inc == N - (flipped_row_count * 2) and flipped_col_count < N:
            answer.append(f'C {flipped_col_count + 1}')
            flipped_col_count += 1
        elif inc == -(N - (flipped_row_count * 2)) and flipped_col_count > 0:
            answer.append(f'C {flipped_col_count}')
            flipped_col_count -= 1
        else:
            print('-1')
            break
    else:
        print('\n'.join(answer))


if __name__ == '__main__':
    main()