結果

問題 No.1016 三目並べ
ユーザー dn6049949dn6049949
提出日時 2020-04-03 22:36:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 2,102 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 77,200 KB
最終ジャッジ日時 2023-09-16 03:28:05
合計ジャッジ時間 2,449 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,424 KB
testcase_01 AC 100 ms
71,648 KB
testcase_02 AC 99 ms
71,504 KB
testcase_03 AC 104 ms
72,048 KB
testcase_04 AC 107 ms
72,044 KB
testcase_05 AC 104 ms
72,128 KB
testcase_06 AC 99 ms
72,324 KB
testcase_07 AC 132 ms
77,200 KB
testcase_08 AC 130 ms
77,140 KB
testcase_09 AC 135 ms
76,976 KB
testcase_10 AC 138 ms
76,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    t = I()
    f = {"o":0, "x":1, "-":2}
    for _ in range(t):
        n,s = input().split()
        n = int(n)
        if n < 5:
            print("X")
            continue
        c = [0,0,0]
        c[f[s[0]]] += 1
        c[f[s[1]]] += 1
        for i in range(2,n):
            c[f[s[i]]] += 1
            if c == [2,0,1] or c == [3,0,0]:
                print("O")
                break
            c[f[s[i-2]]] -= 1
        else:
            c = [0,0,0]
            c[f[s[0]]] += 1
            c[f[s[1]]] += 1
            c[f[s[2]]] += 1
            for i in range(3,n):
                c[f[s[i]]] += 1
                if c == [1,0,3] and s[i] == "-" and s[i-3] == "-":
                    print("O")
                    break
                c[f[s[i-3]]] -= 1
            else:
                l = 0
                while l < n:
                    if s[l] == "o":
                        r = l+1
                        while r < n and s[r] == "-":
                            r += 1
                        if r < n and s[r] == "o":
                            if not (r-l)&1:
                                print("O")
                                break
                        l = r
                    else:
                        l += 1
                if l == n:
                    print("X")
    return

#Solve
if __name__ == "__main__":
    solve()
0