Submission #12899146


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/













int N; string S; int C[3010], D[3010];
ll dp[3010][3010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;
	rep(i, 0, N) cin >> C[i];
	rep(i, 0, N) cin >> D[i];

	rep(i, 0, N + 1) rep(diff, 0, N + 1) dp[i][diff] = infl;
	dp[0][0] = 0;

	rep(i, 0, N) rep(diff, 0, N) {
		int d = 0;
		if (S[i] == '(') d = 1;
		else d = -1;

		// stay
		if (0 <= diff + d) chmin(dp[i + 1][diff + d], dp[i][diff]);

		// flip
		if (0 <= diff - d) chmin(dp[i + 1][diff - d], dp[i][diff] + C[i]);

		// erase
		chmin(dp[i + 1][diff], dp[i][diff] + D[i]);
	}

	cout << dp[N][0] << endl;
}





Submission Info

Submission Time
Task K - Parentheses
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 1963 Byte
Status AC
Exec Time 68 ms
Memory 74224 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 4
AC × 32
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 6 ms 3680 KB
02.txt AC 2 ms 3572 KB
03.txt AC 64 ms 73996 KB
04.txt AC 65 ms 72232 KB
05.txt AC 65 ms 74036 KB
06.txt AC 63 ms 72184 KB
07.txt AC 64 ms 72936 KB
08.txt AC 62 ms 71852 KB
09.txt AC 63 ms 73272 KB
10.txt AC 68 ms 73384 KB
11.txt AC 65 ms 73856 KB
12.txt AC 65 ms 72008 KB
13.txt AC 8 ms 7668 KB
14.txt AC 7 ms 7944 KB
15.txt AC 59 ms 69996 KB
16.txt AC 23 ms 23492 KB
17.txt AC 26 ms 24412 KB
18.txt AC 52 ms 59400 KB
19.txt AC 7 ms 6648 KB
20.txt AC 21 ms 18340 KB
21.txt AC 61 ms 70820 KB
22.txt AC 38 ms 44504 KB
23.txt AC 65 ms 72588 KB
24.txt AC 61 ms 71976 KB
25.txt AC 67 ms 74224 KB
26.txt AC 22 ms 19936 KB
27.txt AC 41 ms 46676 KB
28.txt AC 35 ms 40392 KB
s1.txt AC 2 ms 3648 KB
s2.txt AC 2 ms 3612 KB
s3.txt AC 2 ms 3544 KB
s4.txt AC 2 ms 3628 KB