結果

問題 No.1053 ゲーミング棒
コンテスト
ユーザー le_panda_noir
提出日時 2020-06-20 22:03:33
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 687 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 815 ms
コンパイル使用メモリ 103,584 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2026-06-10 21:59:04
合計ジャッジ時間 3,063 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <queue>
#include <set>
using namespace std;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int main() {
  int N;
  ins(N);

  deque<int> A;
  rep(i, N) {
    int a; cin >> a;
    if (A.empty() || A.back() != a)
      A.push_back(a);
  }
  int ans = 0;
  if (A.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (A.front() == A.back()) {
    ans = 1;
    A.pop_back();
  }
  set<int> s;
  for (const auto& e:A) {
    if (s.find(e) != s.end()) {
      cout << -1 << endl;
      return 0;
    }
    s.insert(e);
  }
  cout << ans << endl;

  return 0;
}
0