結果

問題 No.1288 yuki collection
ユーザー kyort0nkyort0n
提出日時 2020-11-13 21:53:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,232 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 173,124 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 02:49:19
合計ジャッジ時間 3,240 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 14 ms
4,380 KB
testcase_34 AC 10 ms
4,376 KB
testcase_35 AC 10 ms
4,380 KB
testcase_36 AC 8 ms
4,376 KB
testcase_37 AC 9 ms
4,376 KB
testcase_38 AC 14 ms
4,376 KB
testcase_39 AC 14 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N;
string S;
vector<ll> V;
ll ans = 0;
vector<ll> s;
string yuki = "yuki";

bool used[2005];
l_l dp[2005][5];
void f(ll s) {
    for(int i = s; i <= N; i++) {
        for(int j = 0; j < 5; j++) {
            dp[i][j] = {-INF, 0};
        }
    }
    dp[s][0] = {0, -1};
    for(int i = s; i < N; i++) {
        for(int j = 0; j < 5; j++) {
            chmax(dp[i+1][j], dp[i][j]);
            if(j < 4 and !used[i] and S[i] == yuki[j]) {
                l_l now = {dp[i][j].first + V[i], i};
                chmax(dp[i+1][j+1], now);
            }
        }
    }
    /*
    for(int j = 0; j < 5; j++) {
        for(int i = s; i <= N; i++) {
            cerr << "{" << dp[i][j].first << ", " << dp[i][j].second << "} ";
        }
        cerr << endl;
    }
    */
    ll nowi = N;
    ll nowj = 4;
    ll nowans = 0;
    while(nowj != 0) {
        ll newi = dp[nowi][nowj].second;
        nowans += V[newi];
        used[newi] = true;
        nowi = newi;
        nowj--;
    }
    ans += nowans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> S;
    V.resize(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    for(int i = 0; i < N; i++) {
        if(S[i] != 'y') continue;
        vector<int> v;
        for(int j = i; j < N; j++) {
            if(v.size() == yuki.size()) continue;
            if(used[j]) continue;
            if(S[j] == yuki[v.size()]) v.push_back(j);
        }
        if(v.size() != yuki.size()) continue;
        s.push_back(i);
        for(auto j : v) used[j] = true;
    }
    /*
    for(auto tmp : s) cerr << tmp << " ";
    cerr << endl;
    */
    for(int i = 0; i < N; i++) used[i] = false;
    reverse(s.begin(), s.end());
    for(auto tmp : s) {
        f(tmp);
    }
    cout << ans << endl;
    return 0;
}
0