結果

問題 No.1016 三目並べ
ユーザー tktk_snsntktk_snsn
提出日時 2020-04-03 23:05:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,114 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 11,060 KB
実行使用メモリ 8,316 KB
最終ジャッジ日時 2023-09-16 04:18:21
合計ジャッジ時間 1,103 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,236 KB
testcase_01 AC 18 ms
8,132 KB
testcase_02 AC 16 ms
8,308 KB
testcase_03 AC 17 ms
8,180 KB
testcase_04 AC 17 ms
8,180 KB
testcase_05 AC 17 ms
8,192 KB
testcase_06 AC 18 ms
7,788 KB
testcase_07 AC 43 ms
8,180 KB
testcase_08 AC 40 ms
8,296 KB
testcase_09 AC 52 ms
8,248 KB
testcase_10 AC 55 ms
8,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

win3 = set([
    "ooo",
    "oo-",
    "o-o",
    "-oo",
])
win4 = set([
    "--o-",
    "-o--",
])
win5 = set([
    "o---o",
])


def RunLengthEncoding(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append((S[i], cnt))
        i += 1
    return res


def game(N, S):
    for i in range(N - 2):
        sss = S[i: i + 3]
        if sss in win3:
            return True

    for i in range(N - 3):
        ssss = S[i:i+4]
        if ssss in win4:
            return True

    RLE = RunLengthEncoding(S)
    M = len(RLE)
    for i in range(M - 2):
        k, v = RLE[i]
        if k == "o":
            kc, vc = RLE[i+1]
            if kc == "-" and vc % 2 == 1 and RLE[i+2][0] == "o":
                return True
    return False


if __name__ == "__main__":
    T = int(input())
    ans = []
    for _ in range(T):
        _, S = input().split()
        N = len(S)
        if game(N, S):
            ans.append("O")
        else:
            ans.append("X")
    print(*ans, sep="\n")
    
0