結果

問題 No.1995 CHIKA Road
ユーザー zawakasuzawakasu
提出日時 2022-07-20 20:21:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 2,310 bytes
コンパイル時間 5,413 ms
コンパイル使用メモリ 239,024 KB
実行使用メモリ 31,140 KB
最終ジャッジ日時 2023-09-15 10:16:41
合計ジャッジ時間 8,228 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 12 ms
4,752 KB
testcase_07 AC 42 ms
8,432 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 45 ms
5,628 KB
testcase_11 AC 277 ms
31,140 KB
testcase_12 AC 146 ms
17,020 KB
testcase_13 AC 75 ms
12,612 KB
testcase_14 AC 79 ms
11,676 KB
testcase_15 AC 236 ms
27,816 KB
testcase_16 AC 19 ms
5,596 KB
testcase_17 AC 101 ms
12,572 KB
testcase_18 AC 183 ms
20,428 KB
testcase_19 AC 184 ms
17,820 KB
testcase_20 AC 87 ms
12,832 KB
testcase_21 AC 76 ms
12,036 KB
testcase_22 AC 163 ms
19,696 KB
testcase_23 AC 44 ms
8,532 KB
testcase_24 AC 145 ms
17,560 KB
testcase_25 AC 23 ms
6,176 KB
testcase_26 AC 52 ms
9,308 KB
testcase_27 AC 140 ms
16,948 KB
testcase_28 AC 76 ms
11,684 KB
testcase_29 AC 173 ms
18,108 KB
testcase_30 AC 23 ms
6,020 KB
testcase_31 AC 11 ms
4,620 KB
testcase_32 AC 31 ms
7,028 KB
testcase_33 AC 133 ms
16,736 KB
testcase_34 AC 12 ms
4,696 KB
testcase_35 AC 50 ms
9,132 KB
testcase_36 AC 59 ms
9,976 KB
testcase_37 AC 163 ms
18,616 KB
testcase_38 AC 109 ms
14,568 KB
testcase_39 AC 10 ms
4,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
// #include <atcoder/modint>
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/scc>

#define int long long
#define all(x) begin(x), end(x)

using namespace std;
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vp = vector<pii>;
using vvp = vector<vp>;
using vs = vector<string>;
using vvc = vector<vector<char>>;

void debug(vector<int> a) {
    for (auto x : a) cout << x << ' ';
    cout << endl;
}

void debug(vector<vector<int>> a) {
    for (auto y : a) debug(y);
}

template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b and (a = b, true);}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b and (a = b, true);}

const int supl = LONG_LONG_MAX - 100;

template <typename T>
vector<int> compress(const vector<T>& a) {
    vector<T> cp = a;
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    vector<int> res(a.size());
    for (int i = 0 ; i < a.size() ; i++) res[i] = lower_bound(cp.begin(), cp.end(), a[i]) - cp.begin();
    return res;
}

void main_() {
    int n, m; cin >> n >> m;
    vp es(m); for (auto& [a, b] : es) cin >> a >> b;
    sort(all(es));
    map<int, int> comp;
    {
        set<int> st;
        for (auto [a, b] : es) {
            st.emplace(a);
            st.emplace(b);
        }
        st.emplace(n);
        int cnt = 0;
        for (auto x : st) {
            comp[x] = cnt++;
        }
    }

    // cout << endl;
    // for (auto [x, y] : comp) cout << x << ' ' << y << endl;
    // 
    vvi G(comp.size());
    for (auto [a, b] : es) G[comp[a]].emplace_back(comp[b]);
    // 
    // cout << endl;

    // debug(G);

    vi dp(comp.size());
    for (int i = 0 ; i < comp.size() ; i++) {
        for (auto x : G[i]) chmax(dp[x], dp[i] + 1);
        if (i != n - 1) chmax(dp[i + 1], dp[i]);
    }

    cout << 2*(n - 1) - dp.back() << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    main_();

    return 0;
}
0