結果
問題 | No.1016 三目並べ |
ユーザー |
|
提出日時 | 2024-03-12 10:57:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 315 ms |
コンパイル使用メモリ | 82,632 KB |
実行使用メモリ | 78,788 KB |
最終ジャッジ日時 | 2024-09-29 22:14:20 |
合計ジャッジ時間 | 1,499 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 |
ソースコード
import sysimport mathimport bisectfrom heapq import heapify, heappop, heappushfrom collections import deque, defaultdict, Counterfrom functools import lru_cachefrom itertools import accumulate, combinations, permutations, productsys.setrecursionlimit(1000000)MOD = 10 ** 9 + 7MOD99 = 998244353input = lambda: sys.stdin.readline().strip()NI = lambda: int(input())NMI = lambda: map(int, input().split())NLI = lambda: list(NMI())SI = lambda: input()SMI = lambda: input().split()SLI = lambda: list(SMI())EI = lambda m: [NLI() for _ in range(m)]from typing import Listfrom itertools import groupby# RUN LENGTH ENCODING str -> list(tuple())# example) "aabbbbaaca" -> [('a', 2), ('b', 4), ('a', 2), ('c', 1), ('a', 1)]def runLengthEncode(S: str) -> "List[tuple[str, int]]":grouped = groupby(S)res = []for k, v in grouped:res.append((k, int(len(list(v)))))return resdef solve(N, S):if "oo-" in S:return Trueif "-oo" in S:return Trueif "ooo" in S:return Trueif "o-o" in S:return Trueif "--o-" in S:return Trueif "-o--" in S:return TrueR = runLengthEncode(S)for i in range(1, len(R)-1):if R[i-1][0] == R[i+1][0] == "o" and R[i][0] == "-" and R[i][1] % 2:return Truereturn Falsedef main():T = NI()for _ in range(T):N, S = SMI()if solve(N, S):print("O")else:print("X")if __name__ == "__main__":main()