Submission #20181763
Source Code Expand
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = 3.14159265359;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
int h, w;
ll a[1000][1000];
ll d[1000][1000];
ll dp(int y, int x)
{
if (d[y][x] >= 0) return d[y][x];
vector<int> dx { 0, 0,+1,-1};
vector<int> dy {-1,+1, 0, 0};
ll r = 1;
for (int i = 0; i < 4; i++){
int yy = y + dy[i];
int xx = x + dx[i];
if (0 <= yy && yy < h && 0 <= xx && xx < w && a[yy][xx] > a[y][x]){
r += dp(yy, xx);
r %= MOD;
}
}
return (d[y][x] = r);
}
int main()
{
cin >> h >> w;
for (int i = 0; i < h; i++){
for (int j = 0; j < w; j++){
cin >> a[i][j];
d[i][j] = -1;
}
}
ll ans = 0;
for (int y = 0; y < h; y++){
for (int x = 0; x < w; x++){
ans += dp(y, x);
ans %= MOD;
}
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - 経路 |
| User | unnohideyuki |
| Language | C++ (GCC 9.2.1) |
| Score | 100 |
| Code Size | 980 Byte |
| Status | AC |
| Exec Time | 357 ms |
| Memory | 19524 KiB |
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 | 229 ms | 19488 KiB |
| 01.txt | AC | 284 ms | 19524 KiB |
| 02.txt | AC | 162 ms | 19064 KiB |
| 03.txt | AC | 2 ms | 3436 KiB |
| 04.txt | AC | 2 ms | 3628 KiB |
| 05.txt | AC | 2 ms | 3528 KiB |
| 06.txt | AC | 2 ms | 3552 KiB |
| 07.txt | AC | 3 ms | 3624 KiB |
| 08.txt | AC | 2 ms | 3692 KiB |
| 09.txt | AC | 2 ms | 3576 KiB |
| 10.txt | AC | 5 ms | 3880 KiB |
| 11.txt | AC | 357 ms | 19128 KiB |
| 12.txt | AC | 352 ms | 19248 KiB |
| 13.txt | AC | 349 ms | 19220 KiB |
| 14.txt | AC | 351 ms | 19248 KiB |
| 15.txt | AC | 311 ms | 19392 KiB |
| 16.txt | AC | 352 ms | 19252 KiB |
| 17.txt | AC | 348 ms | 19124 KiB |
| 18.txt | AC | 172 ms | 19216 KiB |
| 19.txt | AC | 155 ms | 19248 KiB |
| sample01.txt | AC | 2 ms | 3636 KiB |
| sample02.txt | AC | 2 ms | 3668 KiB |