結果

問題 No.1995 CHIKA Road
ユーザー tnakao0123tnakao0123
提出日時 2022-07-03 01:26:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 54,864 KB
実行使用メモリ 13,164 KB
最終ジャッジ日時 2023-08-18 18:34:17
合計ジャッジ時間 5,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,068 KB
testcase_01 AC 3 ms
9,088 KB
testcase_02 AC 4 ms
9,088 KB
testcase_03 AC 4 ms
9,124 KB
testcase_04 AC 4 ms
9,088 KB
testcase_05 AC 4 ms
9,156 KB
testcase_06 AC 8 ms
9,336 KB
testcase_07 AC 20 ms
9,768 KB
testcase_08 AC 5 ms
9,092 KB
testcase_09 AC 4 ms
9,172 KB
testcase_10 AC 41 ms
10,680 KB
testcase_11 AC 85 ms
13,164 KB
testcase_12 AC 66 ms
13,124 KB
testcase_13 AC 28 ms
10,408 KB
testcase_14 AC 29 ms
10,460 KB
testcase_15 AC 74 ms
12,600 KB
testcase_16 AC 12 ms
9,464 KB
testcase_17 AC 42 ms
10,476 KB
testcase_18 AC 69 ms
11,512 KB
testcase_19 AC 69 ms
11,468 KB
testcase_20 AC 37 ms
10,364 KB
testcase_21 AC 35 ms
10,276 KB
testcase_22 AC 64 ms
11,348 KB
testcase_23 AC 22 ms
9,820 KB
testcase_24 AC 56 ms
11,012 KB
testcase_25 AC 14 ms
9,528 KB
testcase_26 AC 25 ms
9,932 KB
testcase_27 AC 53 ms
10,968 KB
testcase_28 AC 34 ms
10,252 KB
testcase_29 AC 65 ms
11,416 KB
testcase_30 AC 14 ms
9,536 KB
testcase_31 AC 8 ms
9,328 KB
testcase_32 AC 16 ms
9,640 KB
testcase_33 AC 53 ms
10,908 KB
testcase_34 AC 9 ms
9,364 KB
testcase_35 AC 23 ms
9,912 KB
testcase_36 AC 27 ms
10,036 KB
testcase_37 AC 61 ms
11,164 KB
testcase_38 AC 44 ms
10,632 KB
testcase_39 AC 8 ms
9,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1995.cc:  No.1995 CHIKA Road - yukicoder
 */

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

/* constant */

const int MAX_M = 100000;
const int MAX_K = MAX_M * 2 + 2;

/* typedef */

typedef vector<int> vi;

/* global variables */

int as[MAX_M], bs[MAX_M], xs[MAX_K], dp[MAX_K];
vi nbrs[MAX_K];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  int k = 0;
  xs[k++] = 1, xs[k++] = n;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", as + i, bs + i);
    xs[k++] = as[i], xs[k++] = bs[i];
  }
  sort(xs, xs + k);
  k = unique(xs, xs + k) - xs;

  for (int i = 0; i < m; i++) {
    int ai = lower_bound(xs, xs + k, as[i]) - xs;
    int bi = lower_bound(xs, xs + k, bs[i]) - xs;
    nbrs[ai].push_back(bi);
  }

  for (int i = 0; i < k; i++) {
    if (i + 1 < n) setmax(dp[i + 1], dp[i]);
    for (auto j: nbrs[i]) setmax(dp[j], dp[i] + 1);
  }

  printf("%d\n", (n - 1) * 2 - dp[k - 1]);
  return 0;
}
0