結果
| 問題 |
No.1053 ゲーミング棒
|
| コンテスト | |
| ユーザー |
re_re0101
|
| 提出日時 | 2020-05-15 22:13:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,172 bytes |
| コンパイル時間 | 1,642 ms |
| コンパイル使用メモリ | 174,104 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2024-09-19 10:50:32 |
| 合計ジャッジ時間 | 2,747 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
//#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;
}
re_re0101