結果
| 問題 |
No.127 門松もどき
|
| コンテスト | |
| ユーザー |
assy1028
|
| 提出日時 | 2016-12-27 14:01:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,345 bytes |
| コンパイル時間 | 1,092 ms |
| コンパイル使用メモリ | 104,048 KB |
| 実行使用メモリ | 75,484 KB |
| 最終ジャッジ日時 | 2024-12-15 02:05:08 |
| 合計ジャッジ時間 | 3,687 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 WA * 21 |
ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;
#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int n;
int a[3010];
vector<int> l[2][3010];
vector<int> r[2][3010];
int dp[2][3010][3010];
int calc(int s, int t, int b) {
if (dp[b][s][t] < 0) {
if (s == t) {
int res = 1;
for (int i = 0; i < l[b][s].size(); i++) {
for (int j = 0; j < r[b][s].size(); j++) {
res = max(res, 3 + calc(l[b][s][i], r[b][s][j], b));
}
}
dp[b][s][t] = res;
} else {
int res = 0;
if ((b == 0 && a[s] < a[t]) || (b == 1 && a[s] > a[t])) {
for (int i = 0; i < r[b][t].size(); i++) {
if ((b == 0 && a[r[b][t][i]] < a[s]) || (b == 1 && a[r[b][t][i]] > a[s]))
res = max(res, 1 + calc(s, r[b][t][i], b));
}
} else {
for (int i = 0; i < l[b][s].size(); i++) {
if ((b == 0 && a[l[b][s][i]] < a[t]) || (b == 1 && a[l[b][s][i]] > a[t]))
res = max(res, 1 + calc(l[b][s][i], t, b));
}
}
dp[b][s][t] = res;
}
}
return dp[b][s][t];
}
int solve() {
for (int i = 0; i < n; i++) {
for (int j = i-1; j >= 0; j--) {
if ((l[0][i].empty() && a[j] < a[i]) || (!l[0][i].empty() && a[l[0][i].back()] < a[j])) {
l[0][i].push_back(j);
}
if ((l[1][i].empty() && a[j] > a[i]) || (!l[1][i].empty() && a[l[1][i].back()] > a[j])) {
l[1][i].push_back(j);
}
}
for (int j = i+1; j < n; j++) {
if ((r[0][i].empty() && a[j] < a[i]) || (!r[0][i].empty() && a[r[0][i].back()] < a[j])) {
r[0][i].push_back(j);
}
if ((r[1][i].empty() && a[j] > a[i]) || (!r[1][i].empty() && a[r[1][i].back()] > a[j])) {
r[1][i].push_back(j);
}
}
}
memset(dp, -1, sizeof(dp));
int res = 0;
for (int i = 0; i < n; i++) {
res = max(res, max(calc(i, i, 0), calc(i, i, 1)));
}
return res;
}
void input() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
input();
cout << solve() << endl;
}
assy1028