結果

問題 No.1995 CHIKA Road
ユーザー shoshoshomshoshoshom
提出日時 2022-07-02 00:04:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 199,428 KB
最終ジャッジ日時 2025-01-30 03:37:56
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

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

static inline void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> P(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    P[i] = {b, a};
  }
  sort(P.begin(), P.end());
  int now = 1;
  int ans = 2 * (n - 1);
  for (int i = 0; i < m; i++) {
    auto [b, a] = P[i];
    if (now > a) continue;
    now = b;
    ans--;
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef LOCAL
  int T;
  cin >> T;
  for (int tc = 1; tc <= T; tc++) {
    cout << "Case" << tc << ":" << '\n';
    solve();
  }
#else
  solve();
#endif
  return 0;
}
0