結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー Example0911
提出日時 2021-01-29 21:36:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 207,428 KB
最終ジャッジ日時 2025-01-18 08:59:12
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 998244353;
bool f(vector<ll>a) {
	if (a[0] == a[1] || a[1] == a[2] || a[0] == a[2])return false;
	if ((a[1] > a[0] && a[1] > a[2]) || (a[1] < a[0] && a[1] < a[2]))return true;
	else return false;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T; cin >> T;
	for (int _ = 0; _ < T; _++) {
		int N; cin >> N;
		vector<ll>A(N); for (int i = 0; i < N; i++)cin >> A[i];
		vector<P>p;
		for (int i = 0; i < N; i++) {
			p.push_back({ A[i], i });
		}
		sort(p.rbegin(), p.rend());
		vector<bool>ok(N);
		ll ans = 0;
		for (int i = 0; i < N; i++) {
			int now = p[i].second;
			vector<ll>a = { A[now%N], A[(now + 1) % N],A[(now + 2) % N] };
			if (f(a)&& !ok[now%N] && !ok[(now+1)%N]&&!ok[(now+2)%N]) {
				ans += A[now%N];
				ok[now%N] = true;
				ok[(now + 1) % N] = true;
				ok[(now + 2) % N] = true;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
0