結果
問題 | No.921 ずんだアロー |
ユーザー |
|
提出日時 | 2019-11-08 21:40:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 872 bytes |
コンパイル時間 | 1,626 ms |
コンパイル使用メモリ | 171,572 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 01:21:29 |
合計ジャッジ時間 | 2,655 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using P = pair<int, int>;vector<P> RLE(const vector<int>& v) {int tar = v.front();int cnt = 0;vector<P> res;for (int x : v) {if (tar == x) cnt++;else {res.emplace_back(tar, cnt);tar = x;cnt = 1;}}if (cnt > 0) res.emplace_back(tar, cnt);return res;}int main() {cin.tie(0);ios::sync_with_stdio(false);int n;cin >> n;vector<int> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}vector<P> v = RLE(a);int sz = v.size();vector<int> dp(sz + 1, 0);dp[1] = v.front().second;for (int i = 1; i < sz; i++) {dp[i + 1] = max(dp[i] + max(v[i].second - 1, 0), dp[i - 1] + v[i].second);}cout << dp[sz] << "\n";return 0;}