Submission #1370638
Source Code Expand
#include <iostream> #include <cstdio> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; int field[1010][1010]; // グローバル配列なので、宣言した時点で全要素が0に初期化される int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll dp[1010][1010]; ll dfs(int y, int x) { if (dp[y][x] == 0) { for (int i = 0; i < 4; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (field[ny][nx] > field[y][x]) { dp[y][x] += 1 + dfs(ny, nx); } } } return dp[y][x] % MOD; } int main() { int H, W; cin >> H >> W; for (int i = 1; i < H + 1; i++) { for (int j = 1; j < W + 1; j++) { scanf("%d", field[i] + j); } } // メモ化再帰 ll ans = 0; for (int i = 1; i < H + 1; i++) { for (int j = 1; j < W + 1; j++) { if (dp[i][j] == 0) { dp[i][j] = dfs(i, j); } ans += dp[i][j]; ans %= MOD; } } // 解答 cout << ans + H * W << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 経路 |
User | university |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 1046 Byte |
Status | AC |
Exec Time | 161 ms |
Memory | 12288 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:31:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", field[i] + j); ^
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 | 121 ms | 12288 KB |
01.txt | AC | 120 ms | 12288 KB |
02.txt | AC | 104 ms | 12160 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 | 2 ms | 2560 KB |
11.txt | AC | 161 ms | 12160 KB |
12.txt | AC | 161 ms | 12288 KB |
13.txt | AC | 160 ms | 12160 KB |
14.txt | AC | 161 ms | 12160 KB |
15.txt | AC | 138 ms | 12288 KB |
16.txt | AC | 161 ms | 12160 KB |
17.txt | AC | 161 ms | 12160 KB |
18.txt | AC | 108 ms | 12160 KB |
19.txt | AC | 88 ms | 12160 KB |
sample01.txt | AC | 2 ms | 2304 KB |
sample02.txt | AC | 2 ms | 2304 KB |