結果
問題 | No.209 Longest Mountain Subsequence |
ユーザー | inu_hir0shi |
提出日時 | 2015-05-15 23:21:15 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 3,341 bytes |
コンパイル時間 | 1,593 ms |
コンパイル使用メモリ | 165,312 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 04:17:14 |
合計ジャッジ時間 | 2,246 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
5,248 KB |
testcase_01 | AC | 32 ms
5,376 KB |
testcase_02 | AC | 30 ms
5,376 KB |
testcase_03 | AC | 99 ms
5,376 KB |
testcase_04 | AC | 99 ms
5,376 KB |
testcase_05 | AC | 25 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> PII; typedef long long LL; typedef unsigned long long ULL; template<class T> inline bool amax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool amin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template<class T> ostream& operator << (ostream &os, const vector<T> &v) { os << "["; for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); it++) { os << (it != v.begin() ? ", " : "") << *it; } os << "]"; return os; } template<class T> ostream& operator << (ostream &os, const set<T> &s) { os << "["; for (typename set<T>::const_iterator it = s.begin(); it != s.end(); it++) { os << (it != s.begin() ? ", " : "") << *it; } os << "]"; return os; } template<class Key, class Val> ostream& operator << (ostream &os, const map<Key, Val> &m) { os << "{"; for (typename map<Key, Val>::const_iterator it = m.begin(); it != m.end(); it++) { os << (it != m.begin() ? ", " : "") << it->first << ":" << it->second; } os << "}"; return os; } template<class T, class S> ostream& operator << (ostream &os, const pair<T, S> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <class Target, class Source> inline Target lexical_cast (const Source &s) { Target t; stringstream ss; ss << s; ss >> t; return t; } //> v < ^ (clock wise) int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; const int INFI = 1<<28; const long long int INFL = 1LL<<60; const double INFD = 1e+300; const float INFF = 1e+100; const double EPS = 1e-8; int main(){ cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false); LL T; cin >> T; while (T--) { LL n; cin >> n; vector<LL> a(n); for (LL i = 0; i < n; i++) cin >> a[i]; vector<vector<LL> > dp1(110, vector<LL>(110, INFL)); for (LL i = 0; i < n; i++) { dp1[i][0] = 0; for (LL j = 0; j < i; j++) { for (LL k = 0; k < n; k++) { if (dp1[j][k] != INFL && a[j] < a[i] && dp1[j][k] < a[i]-a[j]) { dp1[i][k+1] = min(dp1[i][k+1], a[i]-a[j]); } } } } reverse(a.begin(), a.end()); vector<vector<LL> > dp2(110, vector<LL>(110, INFL)); for (LL i = 0; i < n; i++) { dp2[i][0] = 0; for (LL j = 0; j < i; j++) { for (LL k = 0; k < n; k++) { if (dp2[j][k] != INFL && a[j] < a[i] && dp2[j][k] < a[i]-a[j]) { dp2[i][k+1] = min(dp2[i][k+1], a[i]-a[j]); } } } } reverse(a.begin(), a.end()); LL ans = 0; for (LL i = 0; i < n; i++) { LL tmp1 = 0; LL tmp2 = 0; for (LL j = n-1; j >= 0; j--) { if (dp1[i][j] != INFL) { tmp1 += j; break; } } for (LL j = n-1; j >= 0; j--) { if (dp2[n-i-1][j] != INFL) { tmp2 += j; break; } } LL tmp = tmp1 + tmp2; ans = max(ans, tmp); } cout << ans+1 << endl; } return 0; }