結果
問題 | No.1016 三目並べ |
ユーザー | tktk_snsn |
提出日時 | 2020-04-03 23:05:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 1,114 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-07-03 05:38:53 |
合計ジャッジ時間 | 1,369 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 |
ソースコード
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")