結果
問題 | No.127 門松もどき |
ユーザー | tubo28 |
提出日時 | 2015-01-15 16:04:34 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 232 ms / 5,000 ms |
コード長 | 1,836 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 66,284 KB |
実行使用メモリ | 74,280 KB |
最終ジャッジ日時 | 2023-08-25 13:43:19 |
合計ジャッジ時間 | 3,720 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,496 KB |
testcase_01 | AC | 2 ms
5,432 KB |
testcase_02 | AC | 2 ms
5,588 KB |
testcase_03 | AC | 2 ms
5,396 KB |
testcase_04 | AC | 232 ms
74,124 KB |
testcase_05 | AC | 2 ms
5,652 KB |
testcase_06 | AC | 16 ms
25,196 KB |
testcase_07 | AC | 2 ms
5,724 KB |
testcase_08 | AC | 2 ms
5,692 KB |
testcase_09 | AC | 2 ms
5,544 KB |
testcase_10 | AC | 2 ms
5,540 KB |
testcase_11 | AC | 3 ms
8,120 KB |
testcase_12 | AC | 99 ms
56,656 KB |
testcase_13 | AC | 133 ms
64,940 KB |
testcase_14 | AC | 126 ms
62,924 KB |
testcase_15 | AC | 177 ms
73,072 KB |
testcase_16 | AC | 115 ms
60,772 KB |
testcase_17 | AC | 116 ms
64,940 KB |
testcase_18 | AC | 98 ms
60,860 KB |
testcase_19 | AC | 57 ms
48,336 KB |
testcase_20 | AC | 58 ms
48,348 KB |
testcase_21 | AC | 26 ms
35,648 KB |
testcase_22 | AC | 216 ms
74,172 KB |
testcase_23 | AC | 181 ms
74,280 KB |
testcase_24 | AC | 162 ms
69,104 KB |
testcase_25 | AC | 203 ms
73,076 KB |
testcase_26 | AC | 85 ms
52,552 KB |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cstring> #include <ctime> #include <string> #include <vector> #include <algorithm> #include <cmath> #include <sstream> #include <utility> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i<ll(b); i++) #define rep(i,b) loop(i,0,b) #define each(e,c) for(auto&e:c) #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl) struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}}; #else #define dump(...) #endif template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" "); return os; } int N; int A[100010]; int dp1[3010][3010]; int dp2[3010][3010]; int rec1(int,int); int rec2(int,int); int rec1(int l, int r){ int & res = dp1[l][r]; if(res!=-1) return res; if(l==r) return res = 1; if(A[l] < A[r]) return res = max(rec1(l,r-1), rec2(l+1,r)+1); return res = rec1(l,r-1); } int rec2(int l, int r){ int & res = dp2[l][r]; if(res!=-1) return res; if(l==r) return res = 1; if(A[r] < A[l]) return res = max(rec2(l+1,r), rec1(l,r-1)+1); return res = rec2(l+1,r); } int main(){ while(cin>>N && N){ rep(i,N) cin >> A[i]; rep(i,N)rep(j,N) dp1[i][j] = dp2[i][j] = -1; int ans = 1; rep(i,N){ ans = max(ans, rec1(i,N-1)); ans = max(ans, rec2(0,i)); } cout << ans << endl; } }