結果

問題 No.1053 ゲーミング棒
ユーザー i_mrhji_mrhj
提出日時 2020-05-15 22:30:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,582 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 100,948 KB
実行使用メモリ 14,940 KB
最終ジャッジ日時 2023-10-19 15:20:41
合計ジャッジ時間 3,590 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 40 ms
9,040 KB
testcase_24 AC 41 ms
9,040 KB
testcase_25 AC 54 ms
14,940 KB
testcase_26 AC 55 ms
14,940 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 20 ms
6,668 KB
testcase_31 AC 23 ms
9,832 KB
testcase_32 AC 23 ms
9,832 KB
testcase_33 AC 23 ms
9,832 KB
testcase_34 AC 23 ms
9,832 KB
testcase_35 AC 29 ms
9,836 KB
testcase_36 AC 30 ms
9,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}




int main(void) {

  int n, a[100100];
  cin >> n;
  rep(i, n) cin >> a[i];

  vector< vector<int> > v(n + 1);
  rep(i, n) v[a[i]].push_back(i);

  bool f = true;
  rep(i, n) {
    rep(j, v[i].size()-1) {
      if (v[i][j+1]-v[i][j] > 1) f = false;
      if (!f) break;
    }
    if (!f) break;
  }

  if (f) {
    cout << 0 << endl;
    return 0;
  }

  int j = 0;
  while (a[0] == a[j]) j++;
  vector<int> b;
  for (int i = j; i < n; i++) b.push_back(a[i]);
  rep(i, j) b.push_back(a[0]);

  vector< vector<int> > u(n + 1);
  rep(i, n) u[b[i]].push_back(i);

  f = true;

  rep(i, n) {
    rep(j, u[i].size()-1) {
      if (u[i][j+1]-u[i][j] > 1) f = false;
      if (!f) break;
    }
    if (!f) break;
  }

  if (!f) cout << -1 << endl;
  else cout << 1 << endl;

  return 0;
}
0