結果
| 問題 |
No.1995 CHIKA Road
|
| コンテスト | |
| ユーザー |
zawakasu
|
| 提出日時 | 2022-07-20 20:21:32 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 285 ms / 2,000 ms |
| コード長 | 2,310 bytes |
| コンパイル時間 | 13,866 ms |
| コンパイル使用メモリ | 301,268 KB |
| 最終ジャッジ日時 | 2025-01-30 11:19:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#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;
}
zawakasu