結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
12,288 KB
testcase_01 AC 79 ms
12,288 KB
testcase_02 AC 77 ms
12,416 KB
testcase_03 AC 80 ms
12,288 KB
testcase_04 AC 82 ms
12,032 KB
testcase_05 AC 80 ms
12,160 KB
testcase_06 AC 85 ms
12,160 KB
testcase_07 AC 149 ms
12,672 KB
testcase_08 AC 142 ms
12,416 KB
testcase_09 AC 185 ms
12,544 KB
testcase_10 AC 184 ms
12,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
      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
0