結果

問題 No.1053 ゲーミング棒
ユーザー square1001square1001
提出日時 2020-05-15 21:24:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 87,860 KB
実行使用メモリ 9,196 KB
最終ジャッジ日時 2023-10-19 13:05:48
合計ジャッジ時間 2,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 39 ms
9,196 KB
testcase_24 AC 46 ms
9,196 KB
testcase_25 AC 46 ms
9,196 KB
testcase_26 AC 46 ms
9,196 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 20 ms
6,780 KB
testcase_31 AC 21 ms
6,780 KB
testcase_32 AC 21 ms
6,780 KB
testcase_33 AC 21 ms
6,780 KB
testcase_34 AC 21 ms
6,780 KB
testcase_35 AC 27 ms
6,720 KB
testcase_36 AC 27 ms
6,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int inf = 1012345678;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i]; --A[i];
	}
	vector<vector<int> > G(N);
	for (int i = 0; i < N; ++i) {
		G[A[i]].push_back(i);
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (G[i].empty()) continue;
		int l = inf, r = -inf;
		for (int j : G[i]) {
			l = min(l, j);
			r = max(r, j);
		}
		if (r - l + 1 != G[i].size()) {
			sort(G[i].begin(), G[i].end());
			bool f = true;
			for (int j = 0; j < G[i].size(); ++j) {
				if (G[i][j] != j && G[i][j] != N - (G[i].size() - j)) {
					f = false;
					break;
				}
			}
			if (f) ++ans;
			else {
				ans = -1;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0