编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3096 #1004. 提瓦特大冒险 Compile Error 0 0 ms 0 K C / 1.5 K Met 2023-11-23 3:11:17
显示原始代码
import java.util.HashMap;
import java.util.Scanner;

public
class Explorer {
public
    static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int T = scanner.nextInt();

        int[] A = new int[N - 1];
        for (int i = 0; i < N - 1; i++) {
            A[i] = scanner.nextInt();
        }

        HashMap<Integer, Integer> rewards = new HashMap<>();
        for (int i = 0; i < M; i++) {
            int Xi = scanner.nextInt();
            int Yi = scanner.nextInt();
            rewards.put(Xi, Yi);
        }

        boolean canReach = canReachLastRoom(N, T, A, rewards);
        if (canReach) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

private
    static boolean canReachLastRoom(int N, int timeLimit, int[] travelTimes,
                                    HashMap<Integer, Integer> rewardRooms) {
        int currentTime = timeLimit;

        for (int i = 0; i < N - 1; i++) {
            // Move to the next room
            currentTime -= travelTimes[i];

            // Check if there is a reward in the current room
            if (rewardRooms.containsKey(i + 2)) {
                currentTime += rewardRooms.get(i + 2);
            }

            // If the remaining time is not enough to reach the next room, return false
            if (currentTime <= 0) {
                return false;
            }
        }

        return true;
    }
}

编译信息

/sandbox/1/a.c:1:1: error: unknown type name 'import'
import java.util.HashMap;
^
/sandbox/1/a.c:1:12: error: expected ';' after top level declarator
import java.util.HashMap;
           ^
           ;
/sandbox/1/a.c:2:1: error: unknown type name 'import'
import java.util.Scanner;
^
/sandbox/1/a.c:2:12: error: expected ';' after top level declarator
import java.util.Scanner;
           ^
           ;
/sandbox/1/a.c:4:1: error: unknown type name 'public'
public class Explorer {
^
/sandbox/1/a.c:4:13: error: expected ';' after top level declarator
public class Explorer {
            ^
            ;
6 errors generated.