Submission #2117725


Source Code Expand

#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
typedef pair<int,int> P;
int d[1000][1001];

//dの要素を全てゼロに
void allreset(int h,int w){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            d[i][j]=0;
        }
    }
}
//dの要素全てカウント
int allcount(int h,int w){
    int allcount=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            allcount+=d[i][j];
        }
    }
    return allcount;
}

int main(){
    int h,w;
    cin>>h>>w;
    int a[h][w+1];
    int i,j;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
           cin>>a[i][j];
        }
    }
    int ans=0;
    queue<P> que;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            int count=0;
            que.push(P(i,j));
            allreset(h,w);
            d[i][j]=1;
            while(que.size()){
                P p=que.front();
                que.pop();
                for(int v=0;v<4;v++){
                    int nx=p.first+dx[v],ny=p.second+dy[v];
                    if(0<=nx && nx<h && 0<=ny && ny<w && a[nx][ny]>a[p.first][p.second]){
                        que.push(P(nx,ny));
                        d[nx][ny]+=1;
                    }
                 }
             }
             count=allcount(h,w);
             ans+=count;
        }
    }
    ans%=(1000000000+7);
    cout<<ans<<endl;
    return 0;

}

Submission Info

Submission Time
Task D - 経路
User Yui_1991
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1535 Byte
Status TLE
Exec Time 2139 ms
Memory 558360 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 12
TLE × 12
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 TLE 2136 ms 558360 KB
01.txt TLE 2139 ms 514524 KB
02.txt TLE 2104 ms 8064 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 3 ms 256 KB
08.txt AC 2 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 11 ms 384 KB
11.txt TLE 2104 ms 8064 KB
12.txt TLE 2104 ms 8064 KB
13.txt TLE 2104 ms 8064 KB
14.txt TLE 2104 ms 8064 KB
15.txt TLE 2129 ms 431260 KB
16.txt TLE 2104 ms 8064 KB
17.txt TLE 2104 ms 8064 KB
18.txt TLE 2104 ms 8064 KB
19.txt TLE 2104 ms 8064 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB