結果
| 問題 | No.1288 yuki collection |
| コンテスト | |
| ユーザー |
snow39
|
| 提出日時 | 2020-11-13 22:47:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,700 bytes |
| コンパイル時間 | 1,080 ms |
| コンパイル使用メモリ | 106,228 KB |
| 実行使用メモリ | 816,088 KB |
| 最終ジャッジ日時 | 2024-07-22 21:47:26 |
| 合計ジャッジ時間 | 4,121 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | MLE * 1 -- * 2 |
| other | -- * 40 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
const int L=500;
ll dp[505][505][505];
const ll INF=1e18;
int used[505][505][505];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin>>N;
string S;
cin>>S;
vector<ll> V(N);
rep(i,N) cin>>V[i];
rep(i,L+1) rep(j,L+1) rep(k,L+1) dp[i][j][k]=-1;
dp[0][0][0]=0;
used[0][0][0]=1;
vector<tuple<int,int,int>> v={mkt(0,0,0)};
for(int i=0;i<N;i++){
vector<tuple<int,int,int,ll>> tmp;
for(auto f:v){
int a=get<0>(f);
int b=get<1>(f);
int c=get<2>(f);
int nj=a,nk=b,nl=c;
if(S[i]=='y') nj++;
else if(S[i]=='u'){
nj--;
nk++;
}else if(S[i]=='k'){
nk--;
nl++;
}else if(S[i]=='i'){
nl--;
}
if(nj<0||nk<0||nl<0) continue;
if(nj>L||nk>L||nl>L) continue;
if(3*nj+2*nk+nl>N-i) continue;
if(dp[nj][nk][nl]<dp[a][b][c]+V[i]) tmp.push_back(mkt(nj,nk,nl,dp[a][b][c]+V[i]));
}
for(auto f:tmp){
int a=get<0>(f);
int b=get<1>(f);
int c=get<2>(f);
ll d=get<3>(f);
chmax(dp[a][b][c],d);
if(used[a][b][c]==0){
used[a][b][c]=1;
v.push_back(mkt(a,b,c));
}
}
}
cout<<dp[0][0][0]<<endl;
return 0;
}
snow39