結果
問題 |
No.921 ずんだアロー
|
ユーザー |
|
提出日時 | 2019-11-08 21:33:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 846 bytes |
コンパイル時間 | 1,608 ms |
コンパイル使用メモリ | 171,520 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 01:14:37 |
合計ジャッジ時間 | 2,658 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 5 |
ソースコード
#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], dp[i - 1] + v[i].second); } cout << dp[sz] << "\n"; return 0; }