結果
| 問題 |
No.992 最長増加部分列の数え上げ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-14 23:27:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,452 bytes |
| コンパイル時間 | 2,223 ms |
| コンパイル使用メモリ | 202,012 KB |
| 最終ジャッジ日時 | 2025-01-09 00:32:45 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 41 |
ソースコード
#include <bits/stdc++.h> // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif // clang-format on
/**
* author: knshnb
* created: Fri Feb 14 23:02:23 JST 2020
**/
using pii = pair<Int, Int>;
signed main() {
Int n;
cin >> n;
vector<Int> a(n);
REP(i, n) cin >> a[i];
vector<Int> dp(n, 1e18);
vector<vector<pii>> g(n);
for (Int x : a) {
Int j = lower_bound(dp.begin(), dp.end(), x) - dp.begin();
dp[j] = x;
Int cnt = 0;
if (j > 0) {
auto it = upper_bound(g[j - 1].begin(), g[j - 1].end(), pii(-x, 1e10));
Int minus = it == g[j - 1].begin() ? 0 : prev(it)->second;
int plus = g[j - 1].empty() ? 0 : g[j - 1].back().second;
cnt += plus - minus;
} else {
cnt = 1;
}
Int prv = g[j].empty() ? 0 : g[j].back().second;
g[j].push_back({-x, cnt + prv});
}
Int idx = lower_bound(dp.begin(), dp.end(), 1e18) - dp.begin();
cout << g[idx - 1].back().second << endl;
}