結果

問題 No.2692 How Many Times Reached?
コンテスト
ユーザー ducktail
提出日時 2024-08-01 23:04:48
言語 Ruby
(4.0.6 + ACL)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 58 ms / 2,000 ms
+ 358µs
コード長 891 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2026-08-24 18:29:04
合計ジャッジ時間 5,041 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

module HowManyTimesReached
  def solve(n, ss)
    [(0 ... n).reduce(0){|c, i| c + yoko(n, ss, i)},
     (0 ... n).reduce(0){|c, i| c + tate(n, ss, i)},
     naname(n, ss)].sum
  end
  def yoko(n, ss, i)
    x = (0 ... n).map{|j| ss[i][j]}
    if x.count('A') == n - 1 && x.count('.') == 1
      1
    else
      0
    end
  end
  def tate(n, ss, i)
    x = (0 ... n).map{|j| ss[j][i]}
    if x.count('A') == n - 1 && x.count('.') == 1
      1
    else
      0
    end
  end
  def naname(n, ss)
    ret = 0
    x = (0 ... n).map{|i| ss[i][i]}
    if x.count('A') == n - 1 && x.count('.') == 1
      ret += 1
    end
    x = (0 ... n).map{|i| ss[i][n - 1 - i]}
    if x.count('A') == n - 1 && x.count('.') == 1
      ret += 1
    end
    ret
  end
  module_function :solve, :yoko, :tate, :naname
end

n = gets.chomp.to_i
ss = n.times.map{ gets.chomp }
  
puts HowManyTimesReached.solve(n, ss)
0