結果

問題 No.1868 Teleporting Cyanmond
ユーザー kusagame12
提出日時 2023-11-20 18:50:37
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 670 bytes
コンパイル時間 5,600 ms
コンパイル使用メモリ 74,432 KB
実行使用メモリ 48,164 KB
最終ジャッジ日時 2024-09-26 06:41:15
合計ジャッジ時間 16,480 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] rs = new int[n];
        for(int i = 0 ; i < n - 1 ; i++){
            rs[i] = sc.nextInt();
        }
        rs[n-1] = n;
        
        int now = 1;
        int ans = 0;
        while(rs[now-1] != n){
            int max = -1;
            for(int i = now, len = rs[now-1] ; i < len ; i++){
                max = Math.max(max , rs[i-1]);
            }
            now = max;
            ans++;
        }
        
        System.out.println(ans+1);
    }
}
0