結果

問題 No.921 ずんだアロー
ユーザー risujirohrisujiroh
提出日時 2019-11-08 22:21:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 767 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 169,652 KB
実行使用メモリ 5,512 KB
最終ジャッジ日時 2023-10-13 03:59:31
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 13 ms
5,484 KB
testcase_11 AC 14 ms
5,512 KB
testcase_12 AC 5 ms
4,352 KB
testcase_13 AC 11 ms
5,484 KB
testcase_14 AC 12 ms
5,360 KB
testcase_15 AC 8 ms
4,480 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 13 ms
5,512 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 14 ms
5,384 KB
testcase_24 AC 10 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class Itr> auto rle(Itr first, Itr last) {
  V< pair<decltype(*first), int> > res;
  for (; first != last; ++first) {
    if (res.empty() or res.back().first != *first) {
      res.emplace_back(*first, 1);
    } else {
      ++res.back().second;
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  V<> dp(2);
  for (const auto& e : rle(begin(a), end(a))) {
    V<> ndp(2);
    ndp[0] = max(dp[0], dp[1]);
    ndp[1] = dp[0] + e.second;
    swap(dp, ndp);
  }
  cout << max(dp[0], dp[1]) << '\n';
}
0