Submission #19621


Source Code Expand

Copy
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

    public class Main {
            public static void main(String args[]){
            	Scanner input = new Scanner(System.in);
                   	int N = input.nextInt();
                   	int M = input.nextInt();
                   	String[] st = new String[N];
                   	for(int i = 0 ; i < N ; i++){
                   		st[i] = input.next();
                   	}
                    System.out.println(maximum(N,M,st));
            }
            
          public static double maximum(int N,int M,String[] st){
        	  double[][] akarin = new double[N][M];
        	  Queue<String> q = new PriorityQueue<String>();
        	  int sx = -1;
        	  int sy = -1;
        	  int gx = -1;
        	  int gy = -1;
        	  for(int i = 0 ; i < N ; i++){
        		  for(int j = 0 ; j < M ; j++){
        			  if(st[i].charAt(j) == 's'){
        				  sx = i;
        				  sy = j;
        			  }else if(st[i].charAt(j) == 'g'){
        				  gx = i;
        				  gy = j;
        			  }
        		  }
        	  }
        	  akarin[sx][sy] = 0;
        	  q.add(sx+","+sy+","+50000+","+0);
        	  while(!q.isEmpty()){
        		  
        		  String[] sts = q.poll().split(",");
        		  int x = Integer.parseInt(sts[0]);
        		  int y = Integer.parseInt(sts[1]);
        		  double sc = Double.parseDouble(sts[2]);
        		  int t = Integer.parseInt(sts[3]);
        		  if(y >= 0 && y < N && x-1 >= 0){
        			  if(st[y].charAt(x-1) != 's' && st[y].charAt(x-1) != 'g' && st[y].charAt(x-1) != '#'){
        				  double a = Math.min(sc,(double)((int)st[y].charAt(x-1)-48)*(double)(Math.pow(0.99, t)));
        				  if(akarin[y][x-1] <= a){
        					  //sc = Math.min(sc, a);
        					  akarin[y][x-1] = a;
        					  t++;
        					  q.add((x-1)+","+y+","+a+","+t);
        					  //System.out.println(sc);
        				  }
        			}else if(st[y].charAt(x-1) == 'g'){
        					  if(akarin[y][x-1] <= sc){
        						  akarin[y][x-1] = sc;
        					  }
        			  }
        		  }
        		  
        		  if(y >= 0 && y < N && x+1 < M){
        			  if(st[y].charAt(x+1) != 's' && st[y].charAt(x+1) != 'g' && st[y].charAt(x+1) != '#'){
        				  double a = Math.min(sc,(double)((int)st[y].charAt(x+1)-48)*(double)(Math.pow(0.99, t)));
        				  //System.out.println(a+"oi");
        				  if(akarin[y][x+1] <= a){
                			  //stem.out.println(a+","+(x+1)+","+y);
        					  //sc = Math.min(sc, a);
        					  akarin[y][x+1] = a;
        					  t++;
        					  q.add((x+1)+","+y+","+a+","+t);
        					  //System.out.println(sc);
        				  }
        			  }else if(st[y].charAt(x+1) == 'g'){
        					  if(akarin[y][x+1] <= sc){
        						  akarin[y][x+1] = sc;
        					  }
        			  }
        		  }
        		  
        		  if(x >= 0 && x < M && y-1 >= 0){
        			  if(st[y-1].charAt(x) != 's' && st[y-1].charAt(x) != 'g' && st[y-1].charAt(x) != '#'){
        				  double a = Math.min(sc,(double)((int)st[y-1].charAt(x)-48)*(double)(Math.pow(0.99, t)));
        				  if(akarin[y-1][x] <= a){
        					  //sc = Math.min(sc, a);
        					  akarin[y-1][x] = a;
        					  t++;
        					  q.add(x+","+(y-1)+","+a+","+t);
        					  //System.out.println(sc);
        				  }
        			  }else if(st[y-1].charAt(x) == 'g'){
        				 if(akarin[y-1][x] <= sc){
        						  akarin[y-1][x] = sc;
        				 }
        			  }
        		  }
        			  
        		  if(x >= 0 && x < M && y+1 < N){
        			  if(st[y+1].charAt(x) != 's' && st[y+1].charAt(x) != 'g' && st[y+1].charAt(x) != '#'){
        				  double a = Math.min(sc,(double)((int)st[y+1].charAt(x)-48)*(double)(Math.pow(0.99, t)));
        				  if(akarin[y+1][x] <= a){
        					  //sc = Math.min(sc, a);
        					  akarin[y+1][x] = a;
        					  t++;
        					  q.add(x+","+(y+1)+","+a+","+t);
        					  //System.out.println(sc);
        				  }
        			  }else if(st[y+1].charAt(x) == 'g'){
        					  if(akarin[y+1][x] <= sc){
        						  akarin[y+1][x] = sc;
        					  }
        			  }
        		  }
        	  }
        	  
        	  return akarin[gx][gy];

          }
        

    }

Submission Info

Submission Time
Task C - 暗闇帰り道
User spinical
Language Java (OpenJDK 1.7.0)
Score 0
Code Size 4448 Byte
Status TLE
Exec Time 5401 ms
Memory 145300 KB

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
AC × 1
WA × 7
TLE × 38
MLE × 8
RE × 10
Set Name Test Cases
all 00_mini_01.txt, 00_mini_02.txt, 00_mini_03.txt, 00_mini_04.txt, 00_mini_05.txt, 00_sample_01.txt, 00_sample_02.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 01_rnd_20.txt, 02_maxrnd_01.txt, 02_maxrnd_02.txt, 02_maxrnd_03.txt, 02_maxrnd_04.txt, 02_maxrnd_05.txt, 02_maxrnd_06.txt, 02_maxrnd_07.txt, 02_maxrnd_08.txt, 02_maxrnd_09.txt, 02_maxrnd_10.txt, 02_maxrnd_11.txt, 02_maxrnd_12.txt, 02_maxrnd_13.txt, 02_maxrnd_14.txt, 02_maxrnd_15.txt, 02_maxrnd_16.txt, 02_maxrnd_17.txt, 02_maxrnd_18.txt, 02_maxrnd_19.txt, 03_hard_01.txt, 03_hard_02.txt, 03_hard_03.txt, 03_hard_04.txt, 03_hard_05.txt, 03_hard_06.txt, 03_hard_07.txt, 03_hard_08.txt, 04_open_01.txt, 04_open_02.txt, 05_minihard_01.txt, 05_minihard_02.txt, 05_minihard_03.txt, 05_minihard_04.txt, 05_minihard_05.txt, 05_minihard_06.txt, 05_minihard_07.txt, 05_minihard_08.txt
Case Name Status Exec Time Memory
00_mini_01.txt WA 164 ms 7604 KB
00_mini_02.txt WA 154 ms 7644 KB
00_mini_03.txt RE 144 ms 7540 KB
00_mini_04.txt WA 144 ms 7604 KB
00_mini_05.txt WA 145 ms 7660 KB
00_sample_01.txt AC 146 ms 7536 KB
00_sample_02.txt TLE 5116 ms 123104 KB
01_rnd_01.txt TLE 5165 ms 131184 KB
01_rnd_02.txt TLE 5052 ms 140480 KB
01_rnd_03.txt TLE 5189 ms 139572 KB
01_rnd_04.txt TLE 5170 ms 144352 KB
01_rnd_05.txt RE 183 ms 9436 KB
01_rnd_06.txt TLE 5055 ms 141836 KB
01_rnd_07.txt RE 203 ms 10980 KB
01_rnd_08.txt TLE 5401 ms 144072 KB
01_rnd_09.txt TLE 5138 ms 141096 KB
01_rnd_10.txt RE 231 ms 12412 KB
01_rnd_11.txt TLE 5138 ms 144388 KB
01_rnd_12.txt RE 227 ms 11488 KB
01_rnd_13.txt RE 198 ms 10684 KB
01_rnd_14.txt RE 235 ms 12260 KB
01_rnd_15.txt TLE 5221 ms 121824 KB
01_rnd_16.txt TLE 5179 ms 140812 KB
01_rnd_17.txt TLE 5194 ms 139356 KB
01_rnd_18.txt RE 199 ms 10732 KB
01_rnd_19.txt RE 204 ms 11692 KB
01_rnd_20.txt RE 194 ms 10188 KB
02_maxrnd_01.txt TLE 5140 ms 135100 KB
02_maxrnd_02.txt TLE 5053 ms 143540 KB
02_maxrnd_03.txt MLE 0 ms 139400 KB
02_maxrnd_04.txt TLE 5054 ms 141608 KB
02_maxrnd_05.txt MLE 0 ms 144532 KB
02_maxrnd_06.txt TLE 5054 ms 138988 KB
02_maxrnd_07.txt MLE 0 ms 142896 KB
02_maxrnd_08.txt TLE 5128 ms 142856 KB
02_maxrnd_09.txt MLE 0 ms 142076 KB
02_maxrnd_10.txt TLE 5056 ms 100020 KB
02_maxrnd_11.txt MLE 0 ms 143340 KB
02_maxrnd_12.txt TLE 5054 ms 142128 KB
02_maxrnd_13.txt TLE 5050 ms 127200 KB
02_maxrnd_14.txt TLE 5051 ms 127840 KB
02_maxrnd_15.txt TLE 5208 ms 145300 KB
02_maxrnd_16.txt TLE 5149 ms 122504 KB
02_maxrnd_17.txt TLE 5180 ms 138664 KB
02_maxrnd_18.txt WA 248 ms 13428 KB
02_maxrnd_19.txt WA 805 ms 39856 KB
03_hard_01.txt TLE 5190 ms 126696 KB
03_hard_02.txt TLE 5052 ms 111128 KB
03_hard_03.txt TLE 5048 ms 91828 KB
03_hard_04.txt MLE 0 ms 105456 KB
03_hard_05.txt TLE 5211 ms 124568 KB
03_hard_06.txt MLE 0 ms 92680 KB
03_hard_07.txt TLE 5051 ms 82288 KB
03_hard_08.txt TLE 5041 ms 54452 KB
04_open_01.txt TLE 5049 ms 106788 KB
04_open_02.txt TLE 5054 ms 138984 KB
05_minihard_01.txt TLE 5109 ms 123084 KB
05_minihard_02.txt TLE 5052 ms 118536 KB
05_minihard_03.txt WA 1002 ms 38904 KB
05_minihard_04.txt MLE 1228 ms 77612 KB
05_minihard_05.txt TLE 5091 ms 121984 KB
05_minihard_06.txt TLE 5147 ms 122192 KB
05_minihard_07.txt TLE 5047 ms 84252 KB
05_minihard_08.txt TLE 5045 ms 63944 KB