結果
| 問題 |
No.2692 How Many Times Reached?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-01 23:04:48 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 2,000 ms |
| コード長 | 891 bytes |
| コンパイル時間 | 312 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-08-01 23:04:54 |
| 合計ジャッジ時間 | 6,288 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
コンパイルメッセージ
Syntax OK
ソースコード
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)