結果
問題 | No.1288 yuki collection |
ユーザー |
|
提出日時 | 2021-10-10 23:57:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 5,000 ms |
コード長 | 1,665 bytes |
コンパイル時間 | 3,591 ms |
コンパイル使用メモリ | 183,832 KB |
最終ジャッジ日時 | 2025-01-25 00:03:55 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <iostream> #include <sstream> #include <algorithm> #include <stack> #include <vector> #include <queue> #include <map> #include <set> #include <deque> #include <functional> #include <math.h> #include <complex> using namespace std; #include <atcoder/all> using namespace atcoder; #define REP(i,n) for(int i = 0; i < (int)n; i++) #define RREP(i,n) for(int i = (int)n-1; i >= 0; i--) #define LREP(i,n) for(LL i = 0; i < (LL)n; i++) #define Vi vector<int> #define Vl vector<long long> #define LP pair<long long ,long long> #define P pair<int, int> #define T3 tuple<LL, LL, LL> #define T4 tuple<LL, LL, LL, LL> #define INF 1000000007 #define SIZE 400010 #define MOD 998244353 typedef long long LL; LL N; string S; LL V[SIZE]; int main() { cin >> N >> S; REP(i, N) cin >> V[i]; LL X = INF; mcf_graph<LL, LL> graph(N + 2); string T = "yuki"; REP(k, 4) { REP(i, N) { if (S[i] == T[k]) { REP(j, N) { if (j <= i) continue; if (S[j] == T[k]) { graph.add_edge(i, j, INF, 0); break; } } } } } REP(i, N) { if (S[i] == 'y') { graph.add_edge(N, i, INF, 0); break; } } REP(k, 3) { REP(i, N) { if (S[i] == T[k]) { REP(j, N) { if (j <= i) continue; if (S[j] == T[k + 1]) { graph.add_edge(i, j, 1, X - V[i]); break; } } } } } REP(i, N) { if (S[i] == 'i') { graph.add_edge(i, N + 1, 1, X - V[i]); } } vector<LP> res = graph.slope(N, N + 1); LL ans = 0; for (auto p : res) { ans = max(ans, -(p.second - 4 * X * p.first)); } cout << ans << endl; }