結果

問題 No.2708 Jewel holder
ユーザー mkmk
提出日時 2024-03-31 14:17:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,518 bytes
コンパイル時間 3,092 ms
コンパイル使用メモリ 77,380 KB
実行使用メモリ 58,592 KB
最終ジャッジ日時 2024-03-31 14:17:50
合計ジャッジ時間 6,850 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,572 KB
testcase_01 AC 124 ms
57,824 KB
testcase_02 AC 126 ms
57,988 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 126 ms
57,956 KB
testcase_06 AC 126 ms
57,820 KB
testcase_07 WA -
testcase_08 AC 124 ms
57,572 KB
testcase_09 WA -
testcase_10 AC 124 ms
57,744 KB
testcase_11 WA -
testcase_12 AC 150 ms
57,956 KB
testcase_13 WA -
testcase_14 AC 129 ms
56,068 KB
testcase_15 AC 126 ms
57,836 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.util.Scanner;

public class Main {
	
	static int H;
	static int W;
	
	static String[][] A;
	
	static int route = 0;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		H = sc.nextInt();
		W = sc.nextInt();
		
		A = new String[H][W];
		
		for(int h = 0; h < H; h++) {
			String str = sc.next();
			for(int w = 0; w < W; w++) {
				A[h][w] = str.substring(w, w + 1);
			}
		}
		
//		for(int h = 0; h < H; h++) {
//			for(int w = 0; w < W; w++) {
//				System.out.print(A[h][w]);
//				if(w == W - 1) {
//					System.out.println();
//				}
//			}
//		}
		
		rec(0, 0, 1);
		System.out.println(route);
		
	}
	
	static void rec(int x, int y, int jewelry) {
//		System.out.println("(" + x + "," + y + ")" + " jewelry=" + jewelry);
		
		if(x == W - 1 && y == H - 1 && jewelry > 0) {
			route++;
			return;
		}
		
		int jewelry1 = jewelry;
		int jewelry2 = jewelry;
		
		// 右へ移動
		if(x + 1 <= W - 1 && !A[y][x + 1].equals(("#"))) {
			if(A[y][x + 1].equals("o")) {
				jewelry1++;
				rec(x + 1, y, jewelry1);
			}else if(A[y][x + 1].equals("x")) {
				if(jewelry1 < 1) {
					return;
				}else {
					jewelry1--;
					rec(x + 1, y, jewelry1);
				}
			}
		}
		
		
		// 下へ移動
		if(y + 1 <= H - 1 && !A[y + 1][x].equals(("#"))) {
			if(A[y + 1][x].equals("o")) {
				jewelry2++;
				rec(x, y + 1, jewelry2);
			}else if(A[y + 1][x].equals("x")) {
				if(jewelry2 < 1) {
					return;
				}else {
					jewelry2--;
					rec(x, y + 1, jewelry2);
				}
			}
		}
	}
}
0