結果
| 問題 |
No.2591 安上がりな括弧列
|
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2024-10-01 10:05:08 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 665 bytes |
| コンパイル時間 | 6,431 ms |
| コンパイル使用メモリ | 249,112 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-01 10:05:17 |
| 合計ジャッジ時間 | 4,900 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
string S;
cin >> N >> S;
vector<long long> dp(N + 1, 1LL << 60);
dp[0] = 0;
for (int i = 0; i < 2 * N; i++) {
vector<long long> ep(N + 1, 1LL << 60);
int A;
cin >> A;
for (int j = 0; j <= N; j++) {
if (j > 0) {
ep[j - 1] = min(ep[j - 1], dp[j] + (S[i] == '(' ? A : 0));
}
if (j < N) {
ep[j + 1] = min(ep[j + 1], dp[j] + (S[i] == '(' ? 0 : A));
}
}
dp = ep;
}
cout << dp[0] << endl;
}
nonon