結果
| 問題 | 
                            No.1368 サイクルの中に眠る門松列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Nachia
                         | 
                    
| 提出日時 | 2021-01-29 22:00:57 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 35 ms / 2,000 ms | 
| コード長 | 721 bytes | 
| コンパイル時間 | 1,856 ms | 
| コンパイル使用メモリ | 192,320 KB | 
| 最終ジャッジ日時 | 2025-01-18 09:13:40 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 15 | 
コンパイルメッセージ
main.cpp: In function ‘void loop()’:
main.cpp:18:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   scanf("%d",&N);
      |   ~~~~~^~~~~~~~~
main.cpp:19:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |   rep(i,N) scanf("%d",&A[i]);
      |            ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:35:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |   int T; scanf("%d",&T);
      |          ~~~~~^~~~~~~~~
            
            ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
bool iskadomatsu(int a,int b,int c){
  if(a==b||b==c||a==c) return false;
  return ((a<b&&c<b)||(a>b&&c>b));
}
int N;
int A[200004];
bool K[200002];
LL dp[200005];
void loop(){
  scanf("%d",&N);
  rep(i,N) scanf("%d",&A[i]);
  rep(i,4) A[N+i]=A[i];
  rep(i,N+2) K[i]=iskadomatsu(A[i],A[i+1],A[i+2]);
  LL ans=0;
  rep(s,3){
    rep(i,N+5) dp[i]=0;
    rep(i,N){
      dp[i+1]=max(dp[i+1],dp[i]);
      if(K[i+s]) dp[i+3]=max(dp[i+3],dp[i]+A[i+s]);
    }
    ans=max(ans,dp[N]);
  }
  printf("%lld\n",ans);
}
int main(){
  int T; scanf("%d",&T);
  while(T--) loop();
  return 0;
}
            
            
            
        
            
Nachia