結果

問題 No.1016 三目並べ
ユーザー lemondolemondo
提出日時 2020-12-22 16:30:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 81,512 KB
実行使用メモリ 77,092 KB
最終ジャッジ日時 2023-10-21 12:59:50
合計ジャッジ時間 7,591 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,312 KB
testcase_01 WA -
testcase_02 AC 40 ms
53,312 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)

T = int(input())
def check(S):
    vic = 0
    vic_prob = set()
    length = len(S)
    for i in range(length-2):
        s = ''.join(S[i:i+3])
        if s=='ooo':
            vic += 1
        elif s=='oo-' or s=='-oo' or s=='o-o':
            vic_prob.add(i+('-oo', 'o-o', 'oo-').index(s))
    cnt = 0
    o = True
    for i in range(length):
        if S[i]=='o':
            o = True
            if cnt % 2==1:
                vic += 1
            cnt = 0
        elif S[i]=='x':
            o = False
            cnt = 0
        else:
            if o:
                cnt += 1
    return vic, len(vic_prob)
        
        

for _ in range(T):
    N, S = input().split()
    N = int(N)
    S = list(S)
    if N<3:
        print('X')
        continue
    v, p = check(S)
    if v>0 or p>0:
        print('O')
        continue
    
    flg = False
    for i in range(N):
        if S[i]=='-':
            S[i] = 'o'
            v, p = check(S)
            if p > 1:
                flg = True
            S[i] = '-'
    if flg:
        print('O')
    else:
        print('X')
            
0