Submission #3811737


Source Code Expand

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=1000*1000*1000+7;

int main(){
  int H,W;
  cin>>H>>W;
  vector<array<int,3> > v;
  int a[H][W];
  lint dp[H][W];
  REP(i,H)REP(j,W){
    cin>>a[i][j];
    array<int,3> e={a[i][j],i,j};
    v.push_back(e);
  }
  sort(ALL(v));
  reverse(ALL(v));
  for(auto e:v){
    int h,w;
    h=e[1];w=e[2];
    dp[h][w]=1;
    if(h>0 and a[h-1][w]>a[h][w])dp[h][w]+=dp[h-1][w];
    dp[h][w]%=p;
    if(h<H-1 and a[h+1][w]>a[h][w])dp[h][w]+=dp[h+1][w];
    dp[h][w]%=p;
    if(w>0 and a[h][w-1]>a[h][w])dp[h][w]+=dp[h][w-1];
    dp[h][w]%=p;
    if(w<W-1 and a[h][w+1]>a[h][w])dp[h][w]+=dp[h][w+1];
    dp[h][w]%=p;
  }
  lint ans=0;
  REP(i,H)REP(j,W){
    ans+=dp[i][j];
    ans%=p;  
  }
  cout<<ans<<endl;
  return 0;
}

Submission Info

Submission Time
Task D - 経路
User tsjmt
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1109 Byte
Status AC
Exec Time 672 ms
Memory 24296 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 472 ms 23784 KB
01.txt AC 499 ms 23656 KB
02.txt AC 383 ms 23784 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 2 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 3 ms 384 KB
11.txt AC 664 ms 23784 KB
12.txt AC 670 ms 23784 KB
13.txt AC 668 ms 23784 KB
14.txt AC 661 ms 23912 KB
15.txt AC 592 ms 23912 KB
16.txt AC 658 ms 23784 KB
17.txt AC 672 ms 24296 KB
18.txt AC 407 ms 23784 KB
19.txt AC 343 ms 23784 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB