結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー |
![]() |
提出日時 | 2021-01-30 18:42:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 911 bytes |
コンパイル時間 | 705 ms |
コンパイル使用メモリ | 73,960 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-28 06:24:50 |
合計ジャッジ時間 | 2,110 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 WA * 11 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int f(int a , int b , int c){ if(a == b || b == c || c == a){ return 0; } if(b < a && b < c){ return a; } if(b > a && b > c){ return a; } return 0; } void solve(){ int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } a.push_back(a[0]); a.push_back(a[1]); long long res = 0; long long cost0 = 0 , cost1 = 0 , cost2 = 0; for (int i = 0; i < n; i++) { if(i % 3 == 0)cost0 += f(a[i] , a[i + 1] , a[i + 2]); if(i % 3 == 1)cost1 += f(a[i] , a[i + 1] , a[i + 2]); if(i % 3 == 2)cost2 += f(a[i] , a[i + 1] , a[i + 2]); } res = max({cost0 , cost1 , cost2}); cout << res << endl; } int main() { int t; cin >> t; while(t--){ solve(); } return 0; }