結果

問題 No.1053 ゲーミング棒
ユーザー Izayoi_R_sakuraIzayoi_R_sakura
提出日時 2020-05-15 22:41:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,942 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 85,276 KB
実行使用メモリ 13,448 KB
最終ジャッジ日時 2024-09-19 11:50:05
合計ジャッジ時間 2,918 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	ll n ; cin >> n ;
	ll f,l ;
	set<ll> s ;
	vvll cnt(n+1,vll(0)) ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		s.insert(a) ;
		if(i==0) f = a ;
		if(i==n-1) l = a ;
		cnt.at(a).emplace_back(i+1) ;
	}
	for(int i=0;i<=n;i++){
		if(cnt.at(i).size()<2) continue ;
		if(cnt.at(i).at(0)==1){
			vll sub ;
			for(int j=0;j<cnt.at(i).size();j++){
				if(j!=0&&cnt.at(i).at(j-1)+1!=cnt.at(i).at(j)) break ;
				sub.emplace_back(cnt.at(i).at(j)) ;
			}
			for(int j=0;j<sub.size();j++) cnt.at(i).emplace_back(sub.at(j)+n) ;
			for(int j=sub.size();j<cnt.at(i).size()-1;j++){
				if(cnt.at(i).at(j+1)-cnt.at(i).at(j)!=1){
					cout << -1 << endl ;
					return 0 ;
				}
			}
		}else{
			for(int j=0;j<cnt.at(i).size()-1;j++){
				if(cnt.at(i).at(j+1)-cnt.at(i).at(j)!=1){
					cout << -1 << endl ;
					return 0 ;
				}
			}
		}
	}
	cout << (f==l)-(s.size()==1) << endl ;
}
0