結果

問題 No.1053 ゲーミング棒
ユーザー Izayoi_R_sakuraIzayoi_R_sakura
提出日時 2020-05-15 22:41:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,942 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 85,140 KB
実行使用メモリ 13,564 KB
最終ジャッジ日時 2023-10-19 15:42:17
合計ジャッジ時間 2,814 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 1 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 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 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 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 65 ms
13,248 KB
testcase_24 AC 85 ms
13,248 KB
testcase_25 AC 84 ms
13,564 KB
testcase_26 AC 82 ms
13,564 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 23 ms
8,496 KB
testcase_31 AC 22 ms
8,500 KB
testcase_32 AC 23 ms
8,496 KB
testcase_33 AC 22 ms
8,500 KB
testcase_34 AC 21 ms
8,500 KB
testcase_35 AC 27 ms
7,584 KB
testcase_36 AC 28 ms
7,584 KB
権限があれば一括ダウンロードができます

ソースコード

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