結果

問題 No.1053 ゲーミング棒
ユーザー misora192
提出日時 2020-06-06 20:53:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 176,204 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-12-23 13:52:16
合計ジャッジ時間 3,960 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	deque<int> deq;
	rep(i, n){
		int a;
		cin >> a;
		deq.push_back(a);
	}

	int x = deq[0];
	while(!deq.empty() && deq.front() == x){
		deq.pop_front();
	}

	bool erased = false;
	while(!deq.empty() && deq.back() == x){
		erased = true;
		deq.pop_back();
	}

	if(deq.empty()){
		cout << 0 << endl;
		exit(0);
	}

	set<int> st;
	st.insert(x);
	x = deq.front();
	while(!deq.empty()){
		if(st.count(deq.front()) == 1){
			cout << -1 << endl;
			exit(0);
		}

		if(deq.front() != x){
			st.insert(x);
			x = deq.front();
		}
		
		deq.pop_front();
	}
	
	if(erased){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
}
0