結果

問題 No.1016 三目並べ
ユーザー simansiman
提出日時 2020-12-28 08:14:32
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 643 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-10 08:40:45
合計ジャッジ時間 2,023 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
12,288 KB
testcase_01 AC 86 ms
12,288 KB
testcase_02 AC 87 ms
12,160 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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 && s[i + 2] == 'o' && s[i + 1] == 'o'
      return true
    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
  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
0