結果

問題 No.1053 ゲーミング棒
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-08 22:47:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 965 bytes
コンパイル時間 2,603 ms
コンパイル使用メモリ 200,468 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-27 06:03:26
合計ジャッジ時間 5,477 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 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 1 ms
4,376 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 8 ms
4,380 KB
testcase_32 AC 8 ms
4,380 KB
testcase_33 AC 8 ms
4,380 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 9 ms
4,376 KB
testcase_36 AC 9 ms
4,380 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;
  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;
}
0