結果

問題 No.1868 Teleporting Cyanmond
ユーザー kusagame12kusagame12
提出日時 2023-11-20 20:39:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 77,780 KB
実行使用メモリ 62,852 KB
最終ジャッジ日時 2023-11-20 20:39:31
合計ジャッジ時間 14,356 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
57,964 KB
testcase_01 AC 120 ms
57,704 KB
testcase_02 AC 134 ms
57,956 KB
testcase_03 AC 476 ms
62,768 KB
testcase_04 AC 455 ms
62,812 KB
testcase_05 AC 216 ms
61,260 KB
testcase_06 AC 277 ms
62,432 KB
testcase_07 AC 402 ms
62,568 KB
testcase_08 AC 346 ms
60,900 KB
testcase_09 AC 418 ms
62,852 KB
testcase_10 AC 481 ms
62,692 KB
testcase_11 AC 195 ms
60,592 KB
testcase_12 AC 342 ms
62,572 KB
testcase_13 AC 389 ms
62,696 KB
testcase_14 AC 482 ms
62,828 KB
testcase_15 AC 455 ms
62,824 KB
testcase_16 AC 252 ms
62,032 KB
testcase_17 AC 298 ms
62,480 KB
testcase_18 AC 517 ms
62,752 KB
testcase_19 AC 499 ms
62,836 KB
testcase_20 AC 500 ms
62,700 KB
testcase_21 AC 547 ms
62,700 KB
testcase_22 AC 506 ms
61,704 KB
testcase_23 AC 517 ms
62,736 KB
testcase_24 AC 490 ms
62,820 KB
testcase_25 AC 483 ms
62,816 KB
testcase_26 AC 520 ms
62,760 KB
testcase_27 AC 523 ms
62,828 KB
権限があれば一括ダウンロードができます

ソースコード

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