编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3027 #1004. 提瓦特大冒险 Compile Error 0 0 ms 0 K Java / 1.1 K Met 2023-11-22 21:59:14
显示原始代码
import java.util.HashMap;

public class Traveler {
    public 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 + 1)) {
                currentTime += rewardRooms.get(i + 1);
            }

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

        return true;
    }

    public static void main(String[] args) {
        int N = 5;
        int timeLimit = 10;
        int[] travelTimes = { 2, 3, 1, 2 };
        HashMap<Integer, Integer> rewardRooms = new HashMap<>();
        rewardRooms.put(2, 5);
        rewardRooms.put(4, 3);

        boolean result = canReachLastRoom(N, timeLimit, travelTimes, rewardRooms);

        System.out.println(result);
    }
}

编译信息

A TimeLimitExceeded encountered while compiling your code.