Submission #774434


Source Code Expand

#include<iostream>
#include<queue>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
#define rep2(x,from,to) for(long long (x)=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 10000000
#define K 1000000007
long long h,w;
long long dx[4]={0,0,1,-1};
long long dy[4]={1,-1,0,0};
long long zu[1004][1004];
long long dp[1004][1004];
vector<PP> array;
long long ans;
int main()
{
	cin>>h>>w;
	rep(i,h)
	{
		rep(j,w)
		{
			cin>>zu[i+1][j+1];
			array.push_back(PP(zu[i+1][j+1],P(i+1,j+1)));
		}
	}
	sort(array.begin(),array.end());
	rep(i,w*h)
	{
		P p=array[i].second;
		rep(k,4)
		{
			if(zu[p.first][p.second]<zu[p.first+dx[k]][p.second+dy[k]])
			{
				dp[p.first+dx[k]][p.second+dy[k]]+=(dp[p.first][p.second]+1);
				dp[p.first+dx[k]][p.second+dy[k]]%=K;
			}
		}
	}
	rep(i,1004)rep(j,1004)
	{
		ans+=dp[i][j];
		ans%=K;
	}
	cout<<(ans+w*h)%K<<endl;
	return 0;
}

Submission Info

Submission Time
Task D - 経路
User musasi
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1095 Byte
Status AC
Exec Time 1536 ms
Memory 39524 KiB

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 921 ms 39524 KiB
01.txt AC 1058 ms 39268 KiB
02.txt AC 616 ms 39396 KiB
03.txt AC 18 ms 256 KiB
04.txt AC 18 ms 256 KiB
05.txt AC 18 ms 256 KiB
06.txt AC 20 ms 256 KiB
07.txt AC 19 ms 384 KiB
08.txt AC 20 ms 384 KiB
09.txt AC 18 ms 256 KiB
10.txt AC 23 ms 896 KiB
11.txt AC 1536 ms 39524 KiB
12.txt AC 1525 ms 39524 KiB
13.txt AC 1515 ms 39524 KiB
14.txt AC 1518 ms 39524 KiB
15.txt AC 1108 ms 39524 KiB
16.txt AC 1518 ms 39524 KiB
17.txt AC 1520 ms 39524 KiB
18.txt AC 647 ms 39524 KiB
19.txt AC 562 ms 31716 KiB
sample01.txt AC 18 ms 256 KiB
sample02.txt AC 19 ms 256 KiB