Submission #721587
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
long long comb [1000] [1000];
int A [1000] [1000];
int H,W;
long long dfs(int i,int j)
{
if(comb [i] [j] != 1){
return comb [i] [j];
}
if(i - 1 >= 0 && A [i - 1] [j] < A [i] [j]){
comb [i] [j] += dfs(i - 1,j);
}
if(i + 1 < H && A [i + 1] [j] < A [i] [j]){
comb [i] [j] += dfs(i + 1,j);
}
if(j - 1 >= 0 && A [i] [j - 1] < A [i] [j]){
comb [i] [j] += dfs(i,j - 1);
}
if(j + 1 < W && A [i] [j + 1] < A [i] [j]){
comb [i] [j] += dfs(i,j + 1);
}
comb [i] [j] %= MOD;
return comb [i] [j];
}
int main(void)
{
scanf("%d %d",&H,&W);
for(int i = 0;i < H;i++){
for(int j = 0;j < W;j++){
scanf("%d",&A [i] [j]);
comb [i] [j] = 1;
}
}
for(int i = 0;i < H;i++){
for(int j = 0;j < W;j++){
if(i - 1 >= 0 && A [i - 1] [j] > A [i] [j]){
continue;
}
else if(i + 1 < H && A [i + 1] [j] > A [i] [j]){
continue;
}
else if(j - 1 >= 0 && A [i] [j - 1] > A [i] [j]){
continue;
}
else if(j + 1 < W && A [i] [j + 1] > A [i] [j]){
continue;
}
dfs(i,j);
}
}
long long ans = 0;
for(int i = 0;i < H;i++){
for(int j = 0;j < W;j++){
ans += comb [i] [j];
ans %= MOD;
}
}
printf("%lld\n",ans);
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - 経路 |
| User |
cmmnd17 |
| Language |
C++14 (GCC 5.4.1) |
| Score |
100 |
| Code Size |
1332 Byte |
| Status |
AC |
| Exec Time |
311 ms |
| Memory |
12032 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:33:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&H,&W);
^
./Main.cpp:36:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&A [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 |
| Case Name |
Status |
Exec Time |
Memory |
| 00.txt |
AC |
208 ms |
12032 KiB |
| 01.txt |
AC |
228 ms |
12032 KiB |
| 02.txt |
AC |
197 ms |
11904 KiB |
| 03.txt |
AC |
4 ms |
256 KiB |
| 04.txt |
AC |
4 ms |
256 KiB |
| 05.txt |
AC |
4 ms |
256 KiB |
| 06.txt |
AC |
4 ms |
256 KiB |
| 07.txt |
AC |
4 ms |
256 KiB |
| 08.txt |
AC |
4 ms |
384 KiB |
| 09.txt |
AC |
4 ms |
256 KiB |
| 10.txt |
AC |
5 ms |
640 KiB |
| 11.txt |
AC |
308 ms |
11904 KiB |
| 12.txt |
AC |
307 ms |
11904 KiB |
| 13.txt |
AC |
309 ms |
11904 KiB |
| 14.txt |
AC |
311 ms |
11904 KiB |
| 15.txt |
AC |
255 ms |
11904 KiB |
| 16.txt |
AC |
311 ms |
11904 KiB |
| 17.txt |
AC |
308 ms |
11904 KiB |
| 18.txt |
AC |
207 ms |
11904 KiB |
| 19.txt |
AC |
179 ms |
11904 KiB |
| sample01.txt |
AC |
4 ms |
256 KiB |
| sample02.txt |
AC |
4 ms |
256 KiB |