結果

問題 No.1868 Teleporting Cyanmond
ユーザー Nzt3
提出日時 2022-09-25 01:57:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 352 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 193,684 KB
最終ジャッジ日時 2025-02-07 14:39:51
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<int>D(N,N);
  for(int i=0;i<N-1;i++){
    int a;
    cin>>a;
    D[a-1]=min(D[a-1],i);
  }
  for(int i=N-2;i>=0;i--){
    D[i]=min(D[i],D[i+1]);
  }
  int ans=0,p=N-1;
  while(p!=0)p=D[p],++ans;
  cout<<ans<<'\n';
}
0