Submission #1071250


Source Code Expand

H, W = gets.split.map(&:to_i)
As = ([[0] * (W + 2)] + readlines.map{|l| [0] + l.split.map(&:to_i) + [0]} + [[0] * (W + 2)]).flatten
MOD = 1_000_000_007

def dp(k)
  return @dp[k] if @dp[k]
  ret = 1
  ret += dp(k + W + 2) if As[k + W + 2] > As[k]
  ret += dp(k - W - 2) if As[k - W - 2] > As[k]
  ret += dp(k + 1) if As[k + 1] > As[k]
  ret += dp(k - 1) if As[k - 1] > As[k]
  @dp[k] = ret
end

@dp = Array.new((H + 2) * (W + 2), nil)
ans = 0
(1 .. H).each do |i|
  (1 .. W).each do |j|
    ans = (ans + dp(i * (W + 2) + j + 1)) % MOD
  end
end
puts ans

Submission Info

Submission Time
Task D - 経路
User noriakiokubo
Language Ruby (2.3.3)
Score 0
Code Size 554 Byte
Status WA
Exec Time 2134 ms
Memory 467608 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 1
WA × 1
AC × 1
WA × 18
TLE × 3
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
Case Name Status Exec Time Memory
00.txt TLE 2122 ms 260652 KB
01.txt TLE 2134 ms 467608 KB
02.txt WA 1064 ms 28916 KB
03.txt WA 11 ms 1788 KB
04.txt WA 11 ms 1788 KB
05.txt WA 11 ms 1788 KB
06.txt WA 12 ms 1916 KB
07.txt WA 12 ms 1916 KB
08.txt WA 11 ms 1788 KB
09.txt WA 11 ms 1788 KB
10.txt WA 14 ms 1916 KB
11.txt WA 1155 ms 36212 KB
12.txt WA 1153 ms 36276 KB
13.txt WA 1209 ms 36344 KB
14.txt WA 1163 ms 36212 KB
15.txt TLE 2119 ms 221536 KB
16.txt WA 1153 ms 36276 KB
17.txt WA 1145 ms 36216 KB
18.txt WA 970 ms 28664 KB
19.txt WA 824 ms 28540 KB
sample01.txt WA 11 ms 1788 KB
sample02.txt AC 11 ms 1788 KB