結果
問題 | No.1804 Intersection of LIS |
ユーザー |
|
提出日時 | 2022-01-07 23:14:03 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 216 ms / 2,000 ms |
コード長 | 1,400 bytes |
コンパイル時間 | 4,482 ms |
コンパイル使用メモリ | 164,792 KB |
実行使用メモリ | 37,168 KB |
最終ジャッジ日時 | 2024-11-14 09:14:20 |
合計ジャッジ時間 | 6,928 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
/** Author: nskybytskyi* Time: 2022-01-07 14:20:00*/#include <bits/stdc++.h>using namespace std;const int inf = numeric_limits<int>::max();// https://cp-algorithms.com/sequences/longest_increasing_subsequence.htmlvector<int> lis(vector<int> const& a) {int n = a.size();vector<int> d(n + 1, inf), ends(n);d[0] = -inf;for (int i = 0; i < n; ++i) {int j = distance(d.begin(), upper_bound(d.begin(), d.end(), a[i]));ends[i] = j;if (d[j - 1] < a[i] && a[i] < d[j]) {d[j] = a[i];}}return ends;}int main() {cin.tie(0)->sync_with_stdio(0);int n;cin >> n;vector<int> p(n);for (auto& pi : p) {cin >> pi;}auto ends = lis(p);for (auto& pi : p) {pi = -pi;}reverse(p.begin(), p.end());auto begins = lis(p);reverse(begins.begin(), begins.end());for (auto& pi : p) {pi = -pi;}reverse(p.begin(), p.end());const int mx = *max_element(ends.begin(), ends.end());vector<vector<int>> elems(mx + 1);for (int i = 0; i < n; ++i) {if (begins[i] + ends[i] == mx + 1) {elems[begins[i]].push_back(p[i]);}}set<int> unique;for (const auto& vec_elem : elems) {if (vec_elem.size() == 1) {unique.insert(vec_elem[0]);}}cout << unique.size() << "\n";for (auto elem : unique) {cout << elem << " ";}cout << "\n";return 0;}