結果

問題 No.921 ずんだアロー
ユーザー RTnFRTnF
提出日時 2019-11-08 22:38:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,089 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 208,332 KB
実行使用メモリ 10,204 KB
最終ジャッジ日時 2023-10-13 04:13:21
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 19 ms
9,604 KB
testcase_11 AC 20 ms
9,808 KB
testcase_12 AC 5 ms
4,740 KB
testcase_13 AC 15 ms
8,028 KB
testcase_14 AC 17 ms
8,628 KB
testcase_15 AC 11 ms
6,368 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 17 ms
8,904 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 21 ms
10,204 KB
testcase_24 AC 11 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

vvll dp;

vll RLE(const vll& s){
    vll ret;
    int ns = s.size();
    int cnt = 0;
    for(int i = 0; i < ns; i++){
        cnt++;
        if((i < ns-1 && s[i] != s[i+1]) || i == ns-1){
            ret.emplace_back(cnt);
            cnt = 0;
        }
    }
    return ret;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    vll b = RLE(a);
    dump(b);
    ll m = SZ(b);
    dp.resize(m, vll(2));
    dp[0][0] = b[0];
    dp[0][1] = 0;
    repr(i, 1, m){
        dp[i][0] = b[i] + dp[i-1][1];
        dp[i][1] = max(dp[i-1][0], dp[i-1][1]);
    }
    cout << max(dp[m-1][0], dp[m-1][1]) << endl;
    return 0;
}
0