結果

問題 No.1053 ゲーミング棒
ユーザー imoni_kawaii
提出日時 2020-06-08 22:53:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 2,876 ms
コンパイル使用メモリ 197,912 KB
最終ジャッジ日時 2025-01-11 00:16:40
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  map<int, int> cnt;
  rep(i, n) {
    if(a[i] != p) cnt[a[i]]++;
    p = a[i];
  }
  int over = 0;
  bool ok = true;
  for(auto e : cnt) {
    if(e.second > 2) ok = false;
    if(e.second == 2) over++;
  }
  if(over > 1) ok = false;
  if(over == 1 && a[0] != a[n-1]) ok = false;
  if(ok) {
    cout << over << '\n';
  }
  else {
    cout << -1 << '\n';
  }
  return 0;
}
0