結果
| 問題 |
No.1368 サイクルの中に眠る門松列
|
| コンテスト | |
| ユーザー |
PCTprobability
|
| 提出日時 | 2021-01-29 21:40:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,352 bytes |
| コンパイル時間 | 1,932 ms |
| コンパイル使用メモリ | 203,280 KB |
| 最終ジャッジ日時 | 2025-01-18 09:03:16 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 WA * 6 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define SIZE(n) int(n.size())
#define P pair<ll,ll>
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll modulo) { ll ret = 1; ll p = a % modulo; while (n) { if (n & 1) ret = ret * p % modulo; p = p * p % modulo; n >>= 1; } return ret; }
bool check(ll a,ll b,ll c){
if((a-b)*(c-b)>0&&a!=c&&b!=c&&a!=b){
return true;
}
return false;
}
void solve(){
ll n;
cin>>n;
vector<ll> a(n);
vcin(a);
vector<bool> t(n);
vector<ll> b(2*n);
for(int i=0;i<n;i++){
b[i]=a[i];
b[i+n]=a[i];
}
for(int i=0;i<n;i++){
t[i]=check(b[i],b[i+1],b[i+2]);
}
vector<vector<ll>> dp(n+3,vector<ll>(4));
vector<ll> m(4);
for(int i=0;i<n;i++){
if(i>=2){
for(int j=0;j<4;j++){
if(t[i]){
dp[i][j]=m[j]+a[i];
}
else{
dp[i][j]=m[j];
}
}
}
else{
if(i==0){
for(int j=0;j<4;j++){
if(t[i]&&j<=1){
dp[i][j]=m[j]+a[i];
}
else{
dp[i][j]=m[j];
}
}
}
if(i==1){
for(int j=0;j<4;j++){
if(t[i]&&j%2==0){
dp[i][j]=m[j]+a[i];
}
else{
dp[i][j]=m[j];
}
}
}
}
if(i>=2){
for(int j=0;j<4;j++){
chmax(m[j],dp[i-2][j]);
}
}
}
ll ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<4;j++){
if((i==n-2&&(j==0||j==2))||(i==n-1&&j!=3)){
continue;
}
chmax(ans,dp[i][j]);
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
cout<<ans<<endl;
}
int main() {
/* mod は 1e9+7 */
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(10);
ll a;
cin>>a;
while(a--){
solve();
}
}
PCTprobability