Submission #1695752


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

const int MAX_N = 110;

int dp[MAX_N][MAX_N][MAX_N];

int main() {
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string s;
    cin >> s;
    int n = s.size();
    rep(i, MAX_N) rep(j, MAX_N) rep(k, MAX_N) dp[i][j][k] = 1e9;
    dp[0][0][0] = 0;

    rep(i, n) rep(j, n) rep(k, n) {
        if(dp[i][j][k] == 1e9) continue;
        if(s[i] == '(') {
            chmin(dp[i+1][j+1][k], dp[i][j][k]);
            if(j > 0) chmin(dp[i+1][j-1][i], dp[i][j][k]+1);
        }
        else {
            if(j > 0) chmin(dp[i+1][j-1][k], dp[i][j][k]);
            chmin(dp[i+1][j+1][i], dp[i][j][k] + 1);
        }
    }

    int ans = 1e9;
    rep(i, n) ans = min(ans, dp[n][0][i]+i);
    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task B - 天下一魔力発電
User T1610
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1522 Byte
Status AC
Exec Time 6 ms
Memory 5504 KB

Judge Result

Set Name All
Score / Max Score 400 / 400
Status
AC × 32
Set Name Test Cases
All 01_sample_01, 01_sample_02, 01_sample_03, 02_manual_01, 02_manual_02, 02_manual_03, 10_random_00, 10_random_01, 10_random_02, 10_random_03, 10_random_04, 10_random_05, 10_random_06, 10_random_07, 10_random_08, 10_random_09, 10_random_10, 10_random_11, 10_random_12, 10_random_13, 10_random_14, 10_random_15, 10_random_16, 10_random_17, 10_random_18, 10_random_19, 20_max_00, 20_max_01, 20_max_02, 20_max_03, 20_max_04, 20_max_05
Case Name Status Exec Time Memory
01_sample_01 AC 4 ms 5376 KB
01_sample_02 AC 4 ms 5504 KB
01_sample_03 AC 4 ms 5376 KB
02_manual_01 AC 4 ms 5504 KB
02_manual_02 AC 4 ms 5504 KB
02_manual_03 AC 4 ms 5376 KB
10_random_00 AC 4 ms 5376 KB
10_random_01 AC 4 ms 5376 KB
10_random_02 AC 4 ms 5376 KB
10_random_03 AC 4 ms 5376 KB
10_random_04 AC 4 ms 5376 KB
10_random_05 AC 4 ms 5376 KB
10_random_06 AC 4 ms 5376 KB
10_random_07 AC 5 ms 5504 KB
10_random_08 AC 4 ms 5376 KB
10_random_09 AC 4 ms 5504 KB
10_random_10 AC 4 ms 5504 KB
10_random_11 AC 4 ms 5376 KB
10_random_12 AC 5 ms 5376 KB
10_random_13 AC 5 ms 5376 KB
10_random_14 AC 4 ms 5376 KB
10_random_15 AC 4 ms 5376 KB
10_random_16 AC 5 ms 5504 KB
10_random_17 AC 5 ms 5376 KB
10_random_18 AC 5 ms 5376 KB
10_random_19 AC 5 ms 5504 KB
20_max_00 AC 6 ms 5504 KB
20_max_01 AC 6 ms 5376 KB
20_max_02 AC 6 ms 5504 KB
20_max_03 AC 6 ms 5504 KB
20_max_04 AC 6 ms 5504 KB
20_max_05 AC 6 ms 5376 KB