結果

問題 No.1288 yuki collection
ユーザー yurujirouyurujirou
提出日時 2021-10-10 23:57:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 1,665 bytes
コンパイル時間 3,790 ms
コンパイル使用メモリ 191,136 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 21:57:12
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 43 ms
4,352 KB
testcase_14 AC 45 ms
4,352 KB
testcase_15 AC 35 ms
4,348 KB
testcase_16 AC 35 ms
4,352 KB
testcase_17 AC 45 ms
4,352 KB
testcase_18 AC 46 ms
4,348 KB
testcase_19 AC 44 ms
4,348 KB
testcase_20 AC 48 ms
4,348 KB
testcase_21 AC 52 ms
4,348 KB
testcase_22 AC 52 ms
4,348 KB
testcase_23 AC 52 ms
4,348 KB
testcase_24 AC 46 ms
4,348 KB
testcase_25 AC 44 ms
4,348 KB
testcase_26 AC 46 ms
4,348 KB
testcase_27 AC 24 ms
4,352 KB
testcase_28 AC 28 ms
4,348 KB
testcase_29 AC 21 ms
4,352 KB
testcase_30 AC 7 ms
4,348 KB
testcase_31 AC 7 ms
4,348 KB
testcase_32 AC 8 ms
4,352 KB
testcase_33 AC 38 ms
4,348 KB
testcase_34 AC 51 ms
4,352 KB
testcase_35 AC 43 ms
4,352 KB
testcase_36 AC 24 ms
4,348 KB
testcase_37 AC 25 ms
4,348 KB
testcase_38 AC 31 ms
4,352 KB
testcase_39 AC 23 ms
4,352 KB
testcase_40 AC 6 ms
4,348 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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