Submission #725977


Source Code Expand

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

import java.util.ArrayList;

class Main{
	
	long[][] memo;
	long[][] a;
	
	public Main(){}
	
	public void run(){
		try{
			Scanner s = new Scanner();
			int h = s.nextInt()+2;
			int w = s.nextInt()+2;
			a = new long[h][w];
			memo = new long[h][w];
			for(int i = 1;i<h-1;i++){
				s.reset();
				for(int j = 1;j<w-1;j++){
					a[i][j] = s.nextLong();
				}
			}
			long count = 0l;
			for(int i = 1;i<h-1;i++){
				for(int j = 1;j<w-1;j++){
					count += calc(a[i][j],i,j) % (long)(Math.pow(10,9)+7);
				}
			}
//			count = count % (long)(Math.pow(10,9)+7);
			System.out.println(count);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	long calc(long value,int h,int w){
		return saiki(value,h-1,w)+saiki(value,h,w-1)+saiki(value,h,w+1)+saiki(value,h+1,w)+1;
	}
	
	long saiki(long value,int h,int w){
		if(a[h][w] <= 0){
			return 0;
		}
		if(a[h][w] <= value){
			return 0;
		}
		if(memo[h][w] != 0){
			return memo[h][w]+1;
		}
		memo[h][w] = saiki(a[h][w],h-1,w)+saiki(a[h][w],h,w-1)+saiki(a[h][w],h,w+1)+saiki(a[h][w],h+1,w);
		if(memo[h][w] == 0){
			return 1;
		}
		return memo[h][w]+1;
	}
	
	public static void main(String[] argv){
		Main main = new Main();
		main.run();
	}
	
	private class Scanner{
		private int p;
		private BufferedReader br;
		String regex = " ";
		String[] token;

		public Scanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
			p = -1;
			token = new String[0];
		}
		
		void setRegex(String str){
			this.regex = str;
		}
		
		void reset(){
			p = -1;
			token = new String[0];
		}
		
		String next() throws IOException{
			if(p < 0){
				String line = br.readLine();
				while("".equals(line))line = br.readLine();
				token = line.split(regex,0);
				p = 0;
				return token[p++];
			}else{
				if(p<token.length)return token[p++];
				p = -1;
				return null;
			}
		}
	
		int nextInt() throws NumberFormatException, IOException{
			return Integer.parseInt(next());
		}
		
		long nextLong() throws NumberFormatException, IOException{
			return Long.parseLong(next());
		
		}
		
		double nextDouble() throws NumberFormatException, IOException{
			return Double.parseDouble(next());
		}
		
		String nextString() throws NumberFormatException, IOException{
			return next();	
		}		
	}
}

Submission Info

Submission Time
Task D - 経路
User shopon1201
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2493 Byte
Status WA
Exec Time 855 ms
Memory 38704 KiB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 19
WA × 2
RE × 1
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 WA 756 ms 37912 KiB
01.txt RE 679 ms 38704 KiB
02.txt AC 735 ms 36820 KiB
03.txt AC 163 ms 7892 KiB
04.txt AC 163 ms 7892 KiB
05.txt AC 167 ms 8020 KiB
06.txt AC 171 ms 8660 KiB
07.txt AC 176 ms 8596 KiB
08.txt AC 171 ms 8020 KiB
09.txt AC 163 ms 8016 KiB
10.txt AC 183 ms 9044 KiB
11.txt AC 839 ms 37460 KiB
12.txt AC 855 ms 37040 KiB
13.txt AC 811 ms 37416 KiB
14.txt AC 819 ms 37988 KiB
15.txt WA 744 ms 37708 KiB
16.txt AC 779 ms 37476 KiB
17.txt AC 791 ms 37560 KiB
18.txt AC 683 ms 37224 KiB
19.txt AC 655 ms 37388 KiB
sample01.txt AC 163 ms 7892 KiB
sample02.txt AC 163 ms 7892 KiB