結果
| 問題 | No.209 Longest Mountain Subsequence |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-02-25 23:15:50 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,443 bytes |
| 記録 | |
| コンパイル時間 | 4,033 ms |
| コンパイル使用メモリ | 349,104 KB |
| 実行使用メモリ | 12,832 KB |
| 最終ジャッジ日時 | 2026-02-25 23:16:34 |
| 合計ジャッジ時間 | 11,374 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge7 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using State = tuple<ll, ll, ll>; // (x, d, cnt)
vector<ll> f(const vector<ll>& lis) {
int n = lis.size();
set<State> dp;
dp.insert({lis[0], 0LL, 1LL});
vector<ll> res;
res.push_back(1);
for (int i = 1; i < n; ++i) {
ll a = lis[i];
set<State> pp = dp; // pp = copy
swap(dp, pp); // dp = old copy, pp = old original
ll max_cnt = 1;
dp.insert({a, 0LL, 1LL});
for (const auto& [x, d, cnt] : pp) {
if (x < a && a - x > d) {
ll nx = a;
ll nd = a - x;
ll ncnt = cnt + 1;
dp.insert({nx, nd, ncnt});
max_cnt = max(max_cnt, ncnt);
}
}
res.push_back(max_cnt);
}
return res;
}
ll solve() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
vector<ll> lefts = f(A);
vector<ll> revA = A;
reverse(revA.begin(), revA.end());
vector<ll> rights = f(revA);
reverse(rights.begin(), rights.end());
ll ans = 0;
for (int i = 0; i < N; ++i) {
ans = max(ans, lefts[i] + rights[i] - 1);
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
cout << solve() << "\n";
}
return 0;
}
norioc