結果

問題 No.1053 ゲーミング棒
ユーザー KoseT
提出日時 2020-05-15 21:52:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 90,092 KB
実行使用メモリ 8,360 KB
最終ジャッジ日時 2024-09-19 09:38:52
合計ジャッジ時間 1,829 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];

  std::unordered_map<int, int> mp;
  int color {A[0]};
  ++mp[A[0]];
  bool is_yes = true;
  bool is_split = false;
  int ans {};

  rep(i, n) {
    if (is_split == true) {
      ans = 1;
      if (A[i] != A[0]) {
        ans = -1;
        break;
      }
    } else if (A[i] != color && mp[A[i]]!=0) {
      if (A[i] == A[0]) {
        is_split = true;
        ans = 1;
      } else {
        ans = -1;
        break;
      }
    } else if (A[i] != color){
      ++mp[A[i]];
      color = A[i];
    }
  }

  cout << ans << '\n';
}
0