Submission #1777613
Source Code Expand
#include<iostream> using namespace std; typedef long long ll; const ll MOD = 1000000007; int H, W; ll dp[1000][1000]; ll in[1000][1000]; const int vx[4] = { 0,-1,0,1 }; const int vy[4] = { 1,0,-1,0 }; ll f(int a, int b) { if (dp[a][b] != 0)return dp[a][b]; ll ans1 = 0; for (int i = 0; i < 4; i++) { int nx = a + vx[i], ny = b + vy[i]; if (nx < 0 || ny < 0 || nx >= H || ny >= W)continue; if (in[a][b] < in[nx][ny])ans1 += f(nx, ny); } return dp[a][b] = (ans1 + 1) % MOD; } int main() { cin >> H >> W; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> in[i][j]; } } ll ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans += f(i, j); ans %= MOD; } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 経路 |
User | Sen |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 810 Byte |
Status | AC |
Exec Time | 426 ms |
Memory | 93440 KB |
Judge Result
Set Name | sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
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 | 254 ms | 16000 KB |
01.txt | AC | 363 ms | 93440 KB |
02.txt | AC | 172 ms | 15872 KB |
03.txt | AC | 2 ms | 2304 KB |
04.txt | AC | 2 ms | 2304 KB |
05.txt | AC | 2 ms | 2304 KB |
06.txt | AC | 2 ms | 2304 KB |
07.txt | AC | 2 ms | 2304 KB |
08.txt | AC | 2 ms | 2432 KB |
09.txt | AC | 2 ms | 2304 KB |
10.txt | AC | 3 ms | 4608 KB |
11.txt | AC | 423 ms | 15872 KB |
12.txt | AC | 423 ms | 15872 KB |
13.txt | AC | 426 ms | 15872 KB |
14.txt | AC | 423 ms | 15872 KB |
15.txt | AC | 375 ms | 16000 KB |
16.txt | AC | 425 ms | 15872 KB |
17.txt | AC | 426 ms | 15872 KB |
18.txt | AC | 181 ms | 15872 KB |
19.txt | AC | 170 ms | 15872 KB |
sample01.txt | AC | 2 ms | 2304 KB |
sample02.txt | AC | 2 ms | 2304 KB |