結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー snrnsidysnrnsidy
提出日時 2021-12-11 02:20:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 849 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 202,524 KB
実行使用メモリ 6,456 KB
最終ジャッジ日時 2023-09-26 06:13:42
合計ジャッジ時間 4,043 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 25 ms
6,148 KB
testcase_08 AC 26 ms
6,244 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;

int main(void) 
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int tc;

  cin >> tc;

  while(tc--)
  {
    int n,t;
    cin >> n;
    vector <long long int> v;
    long long int res = 0;

    for(int i=0;i<n;i++)
    {
      cin >> t;
      v.push_back(t);
    }

    for(int i=0;i<3;i++)
    {
      vector <long long int> dp(n+1,-1);
      dp[0] = 0;

      for(int i=0;i<n;i++)
      {
        dp[i+1] = max(dp[i+1],dp[i]);
        if(i+2 < n)
        {
          if((v[i]==v[i+1]) || (v[i]==v[i+2]) || (v[i+1]==v[i+2]))
          {
            continue;
          }
          dp[i+3] = max(dp[i+3],dp[i] + v[i]);
        }
      }

      res = max(res,dp[n]);
      long long int temp = v[0];
      v.erase(v.begin());
      v.push_back(temp);
    }
    cout << res << '\n';
  }
  return 0;
}
0