結果
問題 |
No.1053 ゲーミング棒
|
ユーザー |
|
提出日時 | 2022-10-10 06:19:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 739 bytes |
コンパイル時間 | 2,334 ms |
コンパイル使用メモリ | 197,808 KB |
最終ジャッジ日時 | 2025-02-08 01:09:14 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector<int> A(N); rep(i,N) cin >> A[i]; vector<pair<int,int>> V = {{A[0], 1}}; rep(i,N) if(i) { if(V.back().first == A[i]) V.back().second++; else V.push_back({A[i], 1}); } int cost = 0; if(V.size() >= 2 && V[0].first == V.back().first) { cost++; V[0].second += V.back().second; V.pop_back(); } vector<int> used(N + 1, 0); for(auto [x, cnt] : V) { if(used[x]){ cout << -1 << endl; return 0; } used[x] = 1; } cout << cost << endl; }