結果

問題 No.1053 ゲーミング棒
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-08 22:53:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 204,828 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2023-08-27 06:16:09
合計ジャッジ時間 3,715 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 36 ms
8,452 KB
testcase_24 AC 52 ms
8,608 KB
testcase_25 AC 54 ms
8,444 KB
testcase_26 AC 54 ms
8,444 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 7 ms
4,376 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 8 ms
4,380 KB
testcase_33 AC 8 ms
4,376 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 8 ms
4,380 KB
testcase_36 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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