結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー Example0911Example0911
提出日時 2021-01-29 21:36:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 213,396 KB
実行使用メモリ 10,760 KB
最終ジャッジ日時 2023-09-09 14:52:39
合計ジャッジ時間 3,773 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 9 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 51 ms
10,352 KB
testcase_06 AC 55 ms
10,516 KB
testcase_07 AC 41 ms
9,720 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 #

#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