結果

問題 No.1016 三目並べ
ユーザー gew1fw
提出日時 2025-06-12 19:53:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 952 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 69,668 KB
最終ジャッジ日時 2025-06-12 19:54:08
合計ジャッジ時間 1,173 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def has_three_consecutive_o(s):
    for i in range(len(s) - 2):
        if s[i] == 'o' and s[i+1] == 'o' and s[i+2] == 'o':
            return True
    return False

def can_o_win(s):
    n = len(s)
    for i in range(n):
        if s[i] != '-':
            continue
        # Check left consecutive o's
        left = 0
        j = i - 1
        while j >= 0 and s[j] == 'o':
            left += 1
            j -= 1
        # Check right consecutive o's
        right = 0
        j = i + 1
        while j < n and s[j] == 'o':
            right += 1
            j += 1
        # Check conditions
        if left + right + 1 >= 3:
            return True
        if left >= 2 or right >= 2:
            return True
    return False

T = int(input())
for _ in range(T):
    N, S = input().split()
    S = list(S)
    if has_three_consecutive_o(S):
        print("O")
        continue
    if can_o_win(S):
        print("O")
    else:
        print("X")
0