結果

問題 No.1053 ゲーミング棒
ユーザー yuki60039
提出日時 2020-05-15 23:32:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 170,476 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 13:51:54
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    vector<int>color;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i==0)color.push_back(a[i]);
        if(i && a[i]!=a[i-1])color.push_back(a[i]);
    }
    int x[n]={};
    int b=0;
    for(int i=0;i<color.size();i++){
        x[color[i]-1]++;
        if(x[color[i]-1]==2){
            b=1;
            if(a[0]!=color[i]||a[n-1]!=color[i]){
                cout<<"-1"<<endl;
                return 0;
            }
        }
        if(x[color[i]-1]==3){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    cout<<b<<endl;
    return 0;
}
0