結果

問題 No.1053 ゲーミング棒
ユーザー わなわな
提出日時 2020-05-16 03:44:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 73,196 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-19 19:53:36
合計ジャッジ時間 2,120 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> a(N);
    for(int i = 0; i < N; i++){
        cin >>  a[i];
        a[i]--;
    }
    vector<int> used(N, 0);
    used[a[0]] = 1;
    int cnt = 1;
    for(int i = 1; i < N; i++){
        if(a[i] != a[i - 1] && used[a[i]] == 1 && i != N - 1){
            cout << -1 << endl;
            return 0;
        }
        else if(a[i] != a[i - 1] && used[a[i]] == 1 && i == N - 1 && a[0] != a[i]){
            cout << -1 << endl;
            return 0;
        }
        else if(a[i] != a[i - 1] && used[a[i]] == 0) {
            cnt++;
            used[a[i]] = 1;
        }
        if(i == N - 1 && a[0] == a[N - 1] && cnt > 1){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}
0