結果

問題 No.1288 yuki collection
ユーザー snow39snow39
提出日時 2020-11-13 22:47:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,700 bytes
コンパイル時間 1,077 ms
コンパイル使用メモリ 104,132 KB
実行使用メモリ 813,640 KB
最終ジャッジ日時 2023-09-30 03:48:29
合計ジャッジ時間 3,747 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0