結果
問題 |
No.1053 ゲーミング棒
|
ユーザー |
![]() |
提出日時 | 2020-07-15 10:59:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 2,053 ms |
コンパイル使用メモリ | 196,012 KB |
最終ジャッジ日時 | 2025-01-11 20:58:56 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair<int,int> P; constexpr int INF = 2e9; int main() { int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i], --a[i]; a.emplace_back(INF); int prev = 0; vector<int> p; for (int i = 0; i <= n; i++) { if (a[i] != a[prev]) { p.emplace_back(a[prev]); prev = i; } } vector<int> cnt(n, 0); bool ok = true; for (int i = 0; i < p.size(); i++) { cnt[p[i]]++; if (cnt[p[i]] > 2) ok = false; } int d = 0; for (int i = 0; i < n; i++) { if (cnt[i] == 2) { d = 1; if (p.back() != p.front()) ok = false; } } if (ok) cout << d << endl; else cout << -1 << endl; return 0; }