結果

問題 No.1053 ゲーミング棒
ユーザー kenken714
提出日時 2020-05-15 21:31:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 1,350 ms
コンパイル使用メモリ 163,968 KB
実行使用メモリ 7,380 KB
最終ジャッジ日時 2024-09-19 09:16:08
合計ジャッジ時間 2,601 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

bool solve(vector<ll> s){
    vector<ll> v, cnt(110000);
    ll n = s.size();
    REP(i, n){
        if (i == n - 1 or s[i] != s[i + 1]) v.push_back(s[i]);
    }
	REP(i, v.size()){
        cnt[v[i]]++;
        if (cnt[v[i]] >= 2) return false;
    }
    return true;
}
int main() {
    ll n;
    cin >> n;
    vector<ll> s(n);
    REP(i, n)
        cin >> s[i];
    if(solve(s)){
        cout << 0 << endl;
        return 0;
    }
	if(s[0] != s[n - 1]){
        cout << -1 << endl;
        return 0;
    }
    while (s[0] == s.back()) s.pop_back();
	if(solve(s)){
        cout << 1 << endl;
        return 0;
    }
	cout << -1 << endl;
}

0