Submission #1125801


Source Code Expand

import java.io.*;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

    
   static long a[][];
static	long c[][];
static int w,h;
   
    public static void main(String[] args) {

	Scanner sc = new Scanner(System.in);
	 h=sc.nextInt();
	 w=sc.nextInt();
	
	a=new long[h][w];
	c=new long[h][w];
	
	for (int i = 0; i < h; i++) {
	    for (int j = 0; j < w; j++) {
		a[i][j]=sc.nextLong();
	    }
	}
	
	for (int i = 0; i < h; i++) {
	    for (int j = 0; j < w; j++) {
		r(i,j);
	    }
	}
	long co = 0;
	
		for (int i = 0; i < h; i++) {
	    for (int j = 0; j < w; j++) {
		co+=c[i][j];
		co %=1000000007;
		System.out.printf("%3d",c[i][j]);
	    }
	     System.out.println("");
	}
	
	System.out.println(co);
	
    }
    
    static long r(int x,int y){
	
	long re=1;
	if(c[x][y]!=-1){
	
	if(x+1<h&&a[x+1][y]>a[x][y])
	    if(c[x+1][y]!=-1)
	   re+= r(x+1,y);
	    else
		re+=c[x+1][y];
	    
		    
	    if(x-1>=0&&a[x-1][y]>a[x][y])
	    if(c[x-1][y]!=-1)
		 re+= r(x-1,y);
	    else
		re+=c[x-1][y];
	   
	    
	    if(y+1<w&&a[x][y+1]>a[x][y])
	    if(c[x][y+1]!=-1)
	   re+= r(x,y+1);
	    else
		re+=c[x][y+1];
	    
	if(y-1>=0&&a[x][y-1]>a[x][y])
	    if(c[x][y-1]!=-1)
	   re+= r(x,y-1);
	    else
		re+=c[x][y-1];
		    
		     c[x][y]=re;
		     
		     
		    return re;
    
	}else{
	return c[x][y];
	
	}
    }
    
    
}

Submission Info

Submission Time
Task D - 経路
User yamacken
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1462 Byte
Status WA
Exec Time 2105 ms
Memory 295896 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 100
Status
WA × 2
WA × 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 2105 ms 255516 KB
01.txt TLE 2105 ms 279916 KB
02.txt TLE 2105 ms 291920 KB
03.txt WA 94 ms 18900 KB
04.txt WA 94 ms 19796 KB
05.txt WA 108 ms 19924 KB
06.txt WA 226 ms 26336 KB
07.txt WA 196 ms 24356 KB
08.txt WA 150 ms 20052 KB
09.txt WA 106 ms 18772 KB
10.txt WA 243 ms 26072 KB
11.txt TLE 2105 ms 294180 KB
12.txt TLE 2105 ms 290720 KB
13.txt TLE 2105 ms 294664 KB
14.txt TLE 2105 ms 295080 KB
15.txt TLE 2105 ms 286684 KB
16.txt TLE 2105 ms 295856 KB
17.txt TLE 2105 ms 292956 KB
18.txt TLE 2105 ms 295896 KB
19.txt TLE 2105 ms 293856 KB
sample01.txt WA 94 ms 18640 KB
sample02.txt WA 98 ms 19796 KB