結果

問題 No.1053 ゲーミング棒
ユーザー m4c_physics99m4c_physics99
提出日時 2020-05-15 23:43:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 170,444 KB
実行使用メモリ 4,700 KB
最終ジャッジ日時 2023-10-19 17:55:42
合計ジャッジ時間 3,186 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 2 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 31 ms
4,700 KB
testcase_24 AC 31 ms
4,700 KB
testcase_25 AC 31 ms
4,700 KB
testcase_26 AC 31 ms
4,700 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 17 ms
4,348 KB
testcase_31 AC 17 ms
4,348 KB
testcase_32 AC 17 ms
4,348 KB
testcase_33 AC 17 ms
4,348 KB
testcase_34 AC 17 ms
4,348 KB
testcase_35 AC 22 ms
4,348 KB
testcase_36 AC 24 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:42:15: warning: 'ng' may be used uninitialized [-Wmaybe-uninitialized]
   42 |   visited[ng] = 1;
      |   ~~~~~~~~~~~~^~~
main.cpp:32:7: note: 'ng' was declared here
   32 |   int ng;
      |       ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int visited[110000];
int main()
{
    int n;cin >>n ;
    int a[n+1];
    rep(i,n)cin >> a[i];
    vector<int> c;
    int now = a[0];
    rep(i,n-1){
        if(a[i+1] != now){
            c.push_back(now);
            now = a[i+1];
        }


    }
    c.push_back(now);
    bool ok = true;
    int m = c.size();
    
    if(m <= 2){
        cout << 0 << endl;
        return 0;
    }
    
    int flag = 0;
  int ng;
    if(c[0] == c[m-1]){
      ng = c[0];
        c.pop_back();
        reverse(c.begin(),c.end());
        c.pop_back();
        flag = 1;
      

    }
  visited[ng] = 1;
    for(auto p:c){
        
        
        if(visited[p])ok = false;
        visited[p] = 1;
    }
    if(ok){
        if(flag)cout << 1 << endl;
        else cout << 0 << endl;


    }
    else{

        cout << -1 << endl;
    }


    return 0;
}
0