結果
| 問題 |
No.1288 yuki collection
|
| ユーザー |
kyort0n
|
| 提出日時 | 2020-11-13 21:53:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,232 bytes |
| コンパイル時間 | 1,782 ms |
| コンパイル使用メモリ | 175,316 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-22 20:45:54 |
| 合計ジャッジ時間 | 3,255 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 27 |
ソースコード
#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;
}
kyort0n