Submission #1127081


Source Code Expand

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
#include<numeric>
#include<sstream>
#include<math.h>
#include <iomanip>
#define ll long long
#define PLL pair<ll,ll>
#define VS vector<string>
#define VL vector<ll>
#define VB vector<bool>
#define VPLL vector<pair<ll,ll> >
#define VVL vector<vector<ll> >
#define VVVL vector<vector<vector<ll> > >
#define VVB vector<vector<bool> >
#define rep(i,a) for (ll i=0;i<a;i++)
#define nrep(i,n,a) for (ll i=n;i<a;i++)
#define mrep(i,a) for(ll i=a;i>=0;i--)
#define INF 1145141919810
#define PI 3.141592653589793238
#define vmin(vec) *std::min_element(vec.begin(),vec.end())
#define vmax(vec) *std::max_element(vec.begin(),vec.end())
#define vsum(vec) std::accumulate(vec.begin(),vec.end(),0LL)
#define ksort(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define ssort(vec) (vec.begin(),vec.end())
#define VPLLsort(vec) sort(vec.begin(), vec.end(),[](PLL &a, PLL &b){ return a.first < b.first; });
#define LTS(n) to_string(n)
#define STL(str) stoll(str)
using namespace std;

ll h, w, mod = 1e9 + 7;
VL dtate{ -1, 0, 1, 0 };
VL dyoko{ 0, 1, 0, -1 };

bool out(ll tate, ll yoko){
	return !(0 <= tate && tate < h && 0 <= yoko && yoko < w);
}

ll dfs(VVL &dp, VVL &a, ll i, ll j){
	if (dp[i][j] != -1) return dp[i][j];
	ll temp;
	temp = 0;
	rep(k, 4) if (!out(i + dtate[k], j + dyoko[k]) && a[i][j]<a[i + dtate[k]][j + dyoko[k]]) temp=(temp+dfs(dp,a,i+dtate[k],j+dyoko[k])+1)%mod;
	dp[i][j] = temp;
	return dp[i][j];
}
 
int main() {
	cin >> h >> w;
	ll sum=1, temp;
	VVL a(h, VL(w, 0)); rep(i, h) rep(j, w) cin >> a[i][j];
	VVL dp(h, VL(w, -1));
	rep(i, h) rep(j, w){
		sum = (sum + dfs(dp,a, i, j))%mod;
	}cout << (sum + h*w)%mod -1<< endl;
	return 0;
}

Submission Info

Submission Time
Task D - 経路
User untan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1831 Byte
Status AC
Exec Time 479 ms
Memory 16128 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 24
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 316 ms 16128 KB
01.txt AC 359 ms 16128 KB
02.txt AC 207 ms 15872 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 2 ms 256 KB
07.txt AC 2 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 2 ms 256 KB
11.txt AC 464 ms 16000 KB
12.txt AC 460 ms 16000 KB
13.txt AC 472 ms 16000 KB
14.txt AC 479 ms 16000 KB
15.txt AC 411 ms 16128 KB
16.txt AC 462 ms 16000 KB
17.txt AC 463 ms 16000 KB
18.txt AC 206 ms 16000 KB
19.txt AC 180 ms 16000 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB