結果

問題 No.1288 yuki collection
ユーザー chocorusk
提出日時 2020-08-14 09:22:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,854 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 124,088 KB
最終ジャッジ日時 2025-01-12 22:29:22
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 RE * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
string s;
ll v[3030];
ll dp[101][27][27][27];
int main()
{
	cin>>n;
    cin>>s;
    for(int i=0; i<n; i++) cin>>v[i];
    assert(n<=100);
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n/4; j++){
            for(int k=0; k<=n/4; k++){
                for(int l=0; l<=n/4; l++){
                    dp[i][j][k][l]=-1;
                }
            }
        }
    }
    dp[0][0][0][0]=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=n/4; j++){
            for(int k=0; k<=n/4; k++){
                for(int l=0; l<=n/4; l++){
                    if(dp[i][j][k][l]==-1) continue;
                    dp[i+1][j][k][l]=max(dp[i+1][j][k][l], dp[i][j][k][l]);
                    if(s[i]=='y'){
                        dp[i+1][j+1][k][l]=max(dp[i+1][j+1][k][l], dp[i][j][k][l]+v[i]);
                    }else if(s[i]=='u'){
                        if(j) dp[i+1][j-1][k+1][l]=max(dp[i+1][j-1][k+1][l], dp[i][j][k][l]+v[i]);
                    }else if(s[i]=='k'){
                        if(k) dp[i+1][j][k-1][l+1]=max(dp[i+1][j][k-1][l+1], dp[i][j][k][l]+v[i]);
                    }else{
                        if(l) dp[i+1][j][k][l-1]=max(dp[i+1][j][k][l-1], dp[i][j][k][l]+v[i]);
                    }
                }
            }
        }
    }
    cout<<dp[n][0][0][0]<<endl;
	return 0;
}
0