結果
| 問題 | No.1053 ゲーミング棒 |
| コンテスト | |
| ユーザー |
imoni_kawaii
|
| 提出日時 | 2020-06-08 22:47:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 965 bytes |
| 記録 | |
| コンパイル時間 | 3,001 ms |
| コンパイル使用メモリ | 191,888 KB |
| 最終ジャッジ日時 | 2025-01-11 00:16:28 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 WA * 5 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }
int n, a[100000];
int main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> n;
rep(i, n) cin >> a[i], a[i]--;
int p = -1;
vector<int> cnt(n, 0);
rep(i, n) {
if(a[i] != p) cnt[a[i]]++;
p = a[i];
}
int over = 0;
bool ok = true;
rep(i, n) {
if(cnt[i] == 0) continue;
if(cnt[i] > 2) ok = false;
else if(over == 0 && cnt[i] == 2) {
over++;
}
else if(over > 0 && cnt[i] == 2) {
ok = false;
}
}
if(ok) {
cout << over << '\n';
}
else {
cout << -1 << '\n';
}
return 0;
}
imoni_kawaii