結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー maimai
提出日時 2021-01-29 20:53:24
言語 cLay
(20240104-1)
結果
WA  
実行時間 -
コード長 528 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 160,788 KB
実行使用メモリ 6,128 KB
最終ジャッジ日時 2023-09-19 02:05:43
合計ジャッジ時間 3,278 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

bool kado(int a, int b, int c) {
  return ((a<b&&b>c)||(a>b&&b<c))&&(a!=c);
}

int N;
ll A[200010];

ll solvep(int N, ll* A) {
  ll ans = 0;
  REP(i, N-2) {
    if (kado(A[i], A[i+1], A[i+2])) {
      ans += A[i];
      i += 2;
    }
  }
  return ans;
}

void solve() {
  rd(N);
  rd(A(N));
  A[N] = A[0];
  A[N+1] = A[1];
  A[N+2] = A[2];
  ll best = 0;
  best = max(best, solvep(N, A));
  best = max(best, solvep(N, A+1));
  best = max(best, solvep(N, A+2));
  wt(best);
}

{
  int T;
  rd(T);
  REP(i, T) {
    solve();
  }
}
0