Submission #1071241


Source Code Expand

if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end
GC.disable

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

def dp(i, j)
  return @dp[i][j] if @dp[i][j]
  ret, a = 1, As[i][j]
  ret += dp(i + 1, j) if As[i + 1][j] > a
  ret += dp(i - 1, j) if As[i - 1][j] > a
  ret += dp(i, j + 1) if As[i][j + 1] > a
  ret += dp(i, j - 1) if As[i][j - 1] > a
  @dp[i][j] = ret
end

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

Submission Info

Submission Time
Task D - 経路
User noriakiokubo
Language Ruby (2.3.3)
Score 0
Code Size 678 Byte
Status TLE
Exec Time 2165 ms
Memory 917192 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 19
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 2138 ms 586684 KB
01.txt TLE 2165 ms 917192 KB
02.txt AC 1177 ms 91072 KB
03.txt AC 50 ms 4156 KB
04.txt AC 51 ms 4160 KB
05.txt AC 50 ms 4160 KB
06.txt AC 51 ms 4296 KB
07.txt AC 52 ms 4288 KB
08.txt AC 51 ms 4164 KB
09.txt AC 50 ms 4164 KB
10.txt AC 54 ms 4424 KB
11.txt AC 1225 ms 98880 KB
12.txt AC 1209 ms 98884 KB
13.txt AC 1224 ms 99008 KB
14.txt AC 1293 ms 98880 KB
15.txt TLE 2145 ms 519364 KB
16.txt AC 1304 ms 98760 KB
17.txt AC 1229 ms 98880 KB
18.txt AC 1024 ms 91460 KB
19.txt AC 834 ms 91464 KB
sample01.txt AC 51 ms 4160 KB
sample02.txt AC 51 ms 4288 KB