結果
問題 |
No.2796 Small Matryoshka
|
ユーザー |
|
提出日時 | 2024-06-28 21:33:58 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,491 bytes |
コンパイル時間 | 2,872 ms |
コンパイル使用メモリ | 259,056 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-06-28 21:34:04 |
合計ジャッジ時間 | 4,859 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 WA * 11 |
ソースコード
#include <bits/stdc++.h> #define mp make_pair #define pb push_back using namespace std; using ll = long long int; template<typename T> ostream& operator+(ostream& out, const vector<T> &vec){ for(const auto &x : vec){ out<<x<<" "; } out<<"\n"; return out; } template<typename T> ostream& operator*(ostream& out, const vector<T> &vec){ for(const auto &x : vec){ out+x; } return out; } template<typename T> istream& operator>>(istream& in, vector<T> &vec){ for(auto &x : vec){ in>>x; } return in; } void solve(){ int n; cin>>n; vector<array<int, 2>> a(n); vector<int> vals; for(auto &[r, R] : a){ cin>>r>>R; vals.push_back(r); vals.push_back(R); } sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); for(auto &[r, R] : a){ r = lower_bound(vals.begin(), vals.end(), r) - vals.begin() + 1; R = lower_bound(vals.begin(), vals.end(), R) - vals.begin() + 1; } vector<int> dp(vals.size() + 1); sort(a.begin(), a.end(), [](const array<int, 2> &a, const array<int, 2> &b){ return a[1] < b[1]; }); for(int i=1,j=0;i<=vals.size();i++){ dp[i] = dp[i-1]; while(j < n && a[j][1] == i){ dp[i] = max(dp[i], dp[a[j][0]] + 1); ++j; } } cout<<n - dp.back()<<"\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }