Submission #1988433


Source Code Expand

Copy
#
# very sorry, hatovalley
# https://beta.atcoder.jp/contests/abc037/submissions/1497549
#
lines = $stdin.read
array = lines.split("\n")
H,W   = array[0].split(" ").map(&:to_i)

# add empty areas around the matrix
A = [Array.new(W+2, 0)]
H.times do |r|
  A << [0] + array[1+r].split(" ").map(&:to_i) + [0]
end
A << Array.new(W+2, 0)

MOD = 10**9+7

dp = Array.new(H + 2) do |i|
  Hash.new do |h, j|
    v = A[i][j]
    u = A[i + 1][j] > v ? dp[i + 1][j] : 0
    d = A[i - 1][j] > v ? dp[i - 1][j] : 0
    r = A[i][j + 1] > v ? dp[i][j + 1] : 0
    l = A[i][j - 1] > v ? dp[i][j - 1] : 0
    h[j] = (u + d + r + l + 1) % MOD
  end
end

ans = 0

for i in 1..H
  for j in 1..W
    #puts "dp[#{i}][#{j}] = #{dp[i][j]}"
    ans += dp[i][j]
  end
  ans %= MOD
end

puts ans

Submission Info

Submission Time
Task D - 経路
User hiroyuking
Language Ruby (2.3.3)
Score 100
Code Size 805 Byte
Status AC
Exec Time 1301 ms
Memory 97788 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 24
Set Name Test Cases
sample sample01.txt, sample02.txt
All 00.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, sample01.txt, sample02.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
00.txt AC 1208 ms 89468 KB
01.txt AC 1183 ms 93948 KB
02.txt AC 1142 ms 78484 KB
03.txt AC 7 ms 1788 KB
04.txt AC 7 ms 1788 KB
05.txt AC 7 ms 1788 KB
06.txt AC 8 ms 1916 KB
07.txt AC 9 ms 3964 KB
08.txt AC 8 ms 1788 KB
09.txt AC 7 ms 1788 KB
10.txt AC 11 ms 2044 KB
11.txt AC 1286 ms 93948 KB
12.txt AC 1301 ms 93948 KB
13.txt AC 1294 ms 93948 KB
14.txt AC 1287 ms 93948 KB
15.txt AC 1263 ms 97788 KB
16.txt AC 1288 ms 93948 KB
17.txt AC 1290 ms 93948 KB
18.txt AC 1115 ms 78588 KB
19.txt AC 991 ms 78588 KB
sample01.txt AC 7 ms 1788 KB
sample02.txt AC 7 ms 1788 KB