結果
| 問題 | No.2591 安上がりな括弧列 | 
| コンテスト | |
| ユーザー |  遭難者 | 
| 提出日時 | 2023-12-19 10:08:20 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 9 ms / 2,000 ms | 
| コード長 | 1,796 bytes | 
| コンパイル時間 | 6,759 ms | 
| コンパイル使用メモリ | 346,428 KB | 
| 実行使用メモリ | 11,264 KB | 
| 最終ジャッジ日時 | 2024-09-27 08:44:29 | 
| 合計ジャッジ時間 | 7,609 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#else
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
#undef long
#define long long long
#define ll long
using namespace std;
using mint = atcoder::modint998244353;
ostream& operator<<(ostream& os, mint& a) {
	return os << a.val();
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& a) {
	const int n = a.size();
	rep(i, n) os << a[i] << " \n"[i + 1 == n];
	return os;
}
template<typename T, size_t n>
ostream& operator<<(ostream& os, array<T, n>& a) {
	rep(i, n) os << a[i] << " \n"[i + 1 == n];
	return os;
}
template<typename T>
istream& operator>>(istream& is, vector<T>& a) {
	for (T& i : a) is >> i;
	return is;
}
template<typename T>
bool chmin(T& x, T y) {
	if (x > y) { x = y; return true; }
	return false;
}
template<typename T>
bool chmax(T& x, T y) {
	if (x < y) { x = y; return true; }
	return false;
}
void solve() {
	int n; string s; cin >> n >> s;
	const int nn = 2 * n;
	vector<int> a(nn); cin >> a;
	constexpr long inf = 1e18;
	vector<vector<long>> d(n + 1, vector<long>(n + 1, inf));
	d[0][0] = 0;
	rep(i, n + 1) rep(j, n + 1) {
		if (i < j) continue;
		const int ij = i + j;
		if (ij == nn) continue;
		if (s[ij] == '(') {
			if (i != n) chmin(d[i + 1][j], d[i][j]);
			if (j != n) chmin(d[i][j + 1], d[i][j] + a[ij]);
		}
		else {
			if (j != n) chmin(d[i][j + 1], d[i][j]);
			if (i != n) chmin(d[i + 1][j], d[i][j] + a[ij]);
		}
	}
	cout << d[n][n] << endl;
}
int main() {
	// srand((unsigned)time(NULL));
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(40);
	solve();
	return 0;
}
            
            
            
        