結果

問題 No.1868 Teleporting Cyanmond
ユーザー tnakao0123
提出日時 2022-03-17 19:18:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 41,924 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-01 18:15:49
合計ジャッジ時間 2,363 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1868.cc:  No.1868 Teleporting Cyanmond - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int rs[MAX_N], ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) scanf("%d", rs + i);

  ds[0] = 0;
  for (int i = 0, j = 1; i < n - 1 && j < n; i++) {
    int dj = ds[i] + 1;
    while (j < rs[i]) ds[j++] = dj;
  }

  printf("%d\n", ds[n - 1]);
  return 0;
}
0