結果
| 問題 |
No.2708 Jewel holder
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 14:17:37 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,518 bytes |
| コンパイル時間 | 2,745 ms |
| コンパイル使用メモリ | 77,228 KB |
| 実行使用メモリ | 54,796 KB |
| 最終ジャッジ日時 | 2024-09-30 19:18:33 |
| 合計ジャッジ時間 | 7,130 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 WA * 10 |
ソースコード
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);
}
}
}
}
}