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
Exec Time 1301 ms
Memory 97788 KB

Test Cases

Set Name Score / Max Score Test Cases
sample 0 / 0 sample01.txt, sample02.txt
All 100 / 100 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 1208 ms 89468 KB
01.txt 1183 ms 93948 KB
02.txt 1142 ms 78484 KB
03.txt 7 ms 1788 KB
04.txt 7 ms 1788 KB
05.txt 7 ms 1788 KB
06.txt 8 ms 1916 KB
07.txt 9 ms 3964 KB
08.txt 8 ms 1788 KB
09.txt 7 ms 1788 KB
10.txt 11 ms 2044 KB
11.txt 1286 ms 93948 KB
12.txt 1301 ms 93948 KB
13.txt 1294 ms 93948 KB
14.txt 1287 ms 93948 KB
15.txt 1263 ms 97788 KB
16.txt 1288 ms 93948 KB
17.txt 1290 ms 93948 KB
18.txt 1115 ms 78588 KB
19.txt 991 ms 78588 KB
sample01.txt 7 ms 1788 KB
sample02.txt 7 ms 1788 KB