結果

問題 No.1053 ゲーミング棒
ユーザー re_re0101re_re0101
提出日時 2020-05-15 22:13:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 175,200 KB
実行使用メモリ 5,984 KB
最終ジャッジ日時 2023-10-19 14:42:18
合計ジャッジ時間 3,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 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 3 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 3 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 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 30 ms
4,884 KB
testcase_24 AC 31 ms
4,884 KB
testcase_25 AC 32 ms
5,940 KB
testcase_26 AC 32 ms
5,940 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 17 ms
4,884 KB
testcase_31 AC 19 ms
5,940 KB
testcase_32 AC 19 ms
5,984 KB
testcase_33 AC 19 ms
5,940 KB
testcase_34 AC 19 ms
5,940 KB
testcase_35 AC 26 ms
5,940 KB
testcase_36 AC 25 ms
5,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=1000000007LL;
const ll MOD=998244353LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll n;cin>>n;
  vl flag(114514);
  vl a(n);
  rep(i,n)cin>>a[i];
  bool ok=true;
  rep(i,n){
    if(i!=n-1){
      if(a[i+1]==a[i])continue;
    }
    if(flag[a[i]])ok=false;
    flag[a[i]]=1;
  }
  if(ok){
    cout<<0<<endl;
    return 0;
  }
  deque<ll>q;
  rep(i,n){
    q.push_back(a[i]);
  }
  while(q.front()==q.back()){
    ll d=q.front();
    q.pop_front();
    q.push_back(d);
  }
  ok=true;
  rep(i,114514)flag[i]=0;
  rep(i,n){
    if(i!=n-1){
      if(q[i+1]==q[i])continue;
    }
    if(flag[q[i]])ok=false;
    flag[q[i]]=1;
  }
  if(ok){
    cout<<1<<endl;
    return 0;
  }
  cout<<-1<<endl;
}
0