Submission #722403


Source Code Expand

#include <iostream>
#include <set>
#include <queue>
#include <utility>
using namespace std;
const int MOD = 1000000007;
int a[1000][1000], dp[1000][1000];
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int h, w;

long long int dfs(int x, int y) {
	if (dp[x][y] != -1) return dp[x][y];
	
	long long int ans = 1;
	for (int i = 0; i < 4; ++i) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx < 0 || w <= nx || ny < 0 || h <= ny
		    || a[x][y] >= a[nx][ny]) {
			continue;
		}
		ans += dfs(nx, ny);
	}
	dp[x][y] = ans % MOD;
	return ans;
}

int main() {
	cin >> h >> w;
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			int z;
			scanf("%d", &z);
			a[x][y] = z;
			
			dp[x][y] = -1;
		}
	}
	
	long long int ans = 0;
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			ans += dfs(x, y);
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task D - 経路
User nahcnuj
Language C++14 (GCC 5.4.1)
Score 100
Code Size 922 Byte
Status AC
Exec Time 332 ms
Memory 8320 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:32:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &z);
                   ^

Judge Result

Set Name sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 22
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 AC 235 ms 8192 KB
01.txt AC 276 ms 8320 KB
02.txt AC 225 ms 8064 KB
03.txt AC 4 ms 256 KB
04.txt AC 4 ms 256 KB
05.txt AC 5 ms 1024 KB
06.txt AC 15 ms 8064 KB
07.txt AC 10 ms 4608 KB
08.txt AC 4 ms 384 KB
09.txt AC 4 ms 256 KB
10.txt AC 5 ms 640 KB
11.txt AC 331 ms 8064 KB
12.txt AC 332 ms 8064 KB
13.txt AC 329 ms 8064 KB
14.txt AC 331 ms 8064 KB
15.txt AC 285 ms 8192 KB
16.txt AC 331 ms 8064 KB
17.txt AC 330 ms 8064 KB
18.txt AC 237 ms 8064 KB
19.txt AC 215 ms 8064 KB
sample01.txt AC 4 ms 256 KB
sample02.txt AC 4 ms 256 KB