結果

問題 No.1868 Teleporting Cyanmond
ユーザー simansiman
提出日時 2022-03-12 01:55:58
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 2,505 ms
コンパイル使用メモリ 143,604 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-16 06:02:30
合計ジャッジ時間 3,425 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

struct Node {
  int idx;
  int r;

  Node(int idx = -1, int r = -1) {
    this->idx = idx;
    this->r = r;
  }

  bool operator>(const Node &n) const {
    return r < n.r;
  }
};

int main() {
  int N;
  cin >> N;
  priority_queue <Node, vector<Node>, greater<Node>> pque;
  for (int i = 1; i <= N - 1; ++i) {
    int r;
    cin >> r;
    pque.push(Node(i, r));
  }

  int ans = 0;
  int cur = N;
  while (cur > 1) {
    int next = N;
    while (not pque.empty() && cur <= pque.top().r) {
      Node node = pque.top();
      next = min(next, node.idx);
      pque.pop();
    }
    cur = next;
    ++ans;
  }

  cout << ans << endl;

  return 0;
}
0