結果

問題 No.1868 Teleporting Cyanmond
ユーザー kusagame12
提出日時 2023-11-20 20:39:16
言語 Java
(openjdk 23)
結果
AC  
実行時間 558 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 73,904 KB
実行使用メモリ 48,132 KB
最終ジャッジ日時 2024-09-26 06:42:49
合計ジャッジ時間 13,673 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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++){
                if(max <= rs[i-1]){
                    max = rs[i-1];
                    now = i;
                }
            }
            ans++;
        }
        
        System.out.println(ans+1);
    }
}
0