結果

問題 No.1053 ゲーミング棒
ユーザー southball02southball02
提出日時 2020-05-15 21:51:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,596 bytes
コンパイル時間 2,492 ms
コンパイル使用メモリ 206,920 KB
実行使用メモリ 5,032 KB
最終ジャッジ日時 2023-10-19 13:26:25
合計ジャッジ時間 3,412 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 2 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 11 ms
4,844 KB
testcase_24 AC 12 ms
4,844 KB
testcase_25 AC 12 ms
4,844 KB
testcase_26 AC 13 ms
4,844 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 9 ms
4,844 KB
testcase_31 AC 10 ms
5,032 KB
testcase_32 AC 9 ms
4,848 KB
testcase_33 AC 9 ms
4,844 KB
testcase_34 AC 8 ms
4,844 KB
testcase_35 AC 11 ms
4,944 KB
testcase_36 AC 11 ms
4,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	vector<int> v(n), lst(n + 1, -1), dis(n + 1, 0);
	int discount = 0;
	rep(i, 0, n) cin >> v[i];
	rep(i, 0, n) {
		if (lst[v[i]] != -1 && i != lst[v[i]] + 1) {
			dis[i] = 1;
			discount++; // www
		}
		lst[v[i]] = i;
	}
	
	if (discount > 1) die(-1);
	if (discount == 0) die(0);

	// shift last block to head
	lst = vi(n + 1, -1); dis = vi(n + 1, 0);

	int tg = v.back(), cnt = 0;
	while (v.size() && v.back() == tg) cnt++, v.pop_back();
	vi tp(cnt, tg);
	v.insert(v.begin(), all(tp));

	discount = 0;
	rep(i, 0, n) {
		if (lst[v[i]] != -1 && i != lst[v[i]] + 1) {
			dis[i] = 1;
			discount++;
		}
		lst[v[i]] = i;
	}
	die(discount == 0 ? 1 : -1);

}
0