Submission #1777598


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 };

void reset() {
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++)dp[i][j] = 0;
}

ll f(int a, int b) {

	if (dp[a][b] != 0)return dp[a][b];

	ll ans = 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])ans += f(nx, ny) + 1;
	}
	return dp[a][b] = ans;
}

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++) {

			reset();

			ans += f(i, j) + 1;
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task D - 経路
User Sen
Language C++14 (GCC 5.4.1)
Score 0
Code Size 909 Byte
Status TLE
Exec Time 2109 ms
Memory 109056 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 12
TLE × 12
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 TLE 2103 ms 16000 KB
01.txt TLE 2109 ms 109056 KB
02.txt TLE 2103 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 8 ms 4608 KB
11.txt TLE 2103 ms 15872 KB
12.txt TLE 2103 ms 15872 KB
13.txt TLE 2103 ms 15872 KB
14.txt TLE 2103 ms 15872 KB
15.txt TLE 2103 ms 16000 KB
16.txt TLE 2103 ms 15872 KB
17.txt TLE 2103 ms 15872 KB
18.txt TLE 2104 ms 15872 KB
19.txt TLE 2103 ms 15872 KB
sample01.txt AC 2 ms 2304 KB
sample02.txt AC 2 ms 2304 KB