結果
問題 | No.1016 三目並べ |
ユーザー |
![]() |
提出日時 | 2020-12-28 08:19:32 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 198 ms / 2,000 ms |
コード長 | 759 bytes |
コンパイル時間 | 44 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,672 KB |
最終ジャッジ日時 | 2024-10-02 10:22:51 |
合計ジャッジ時間 | 2,026 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 |
コンパイルメッセージ
Syntax OK
ソースコード
T = gets.to_i def solver(n, s) n.times do |i| next if s[i] != 'o' if 0 <= i - 1 && i + 1 < n && s[i - 1] == '-' && s[i + 1] == '-' return true if (0 <= i - 2 && s[i - 2] != 'x') || (i + 2 < n && s[i + 2] != 'x') end if i + 2 < n return true if s[i + 1] == 'o' && s[i + 2] == '-' return true if s[i + 1] == '-' && s[i + 2] == 'o' return true if s[i + 1] == 'o' && s[i + 2] == 'o' end if i + 2 < n && s[i + 2] == '-' && s[i + 1] != 'x' s[i + 2] = 'o' if s[i + 1] == 'o' return true end s[i + 1] = 'x' end end false end T.times do |t| n, s = gets.chomp.split n = n.to_i if solver(n, s.dup) || solver(n, s.reverse) puts 'O' else puts 'X' end end