Submission #3374485


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

string s;
int dp[101][101][101];

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>s;
    int n=s.size();
    rep(i,0,n+1)rep(j,0,n+1)rep(k,0,n+1)dp[i][j][k]=INF;
    dp[0][0][0]=0;
    
    rep(i,0,n)rep(j,0,n)rep(k,0,n+1)if(dp[i][j][k]!=INF){
        if(s[i]=='('){
            dp[i+1][j][k+1]=min(dp[i+1][j][k+1],dp[i][j][k]);
            if(0<k)dp[i+1][i][k-1]=min(dp[i+1][i][k-1],dp[i][j][k]+1);
        }else{
            dp[i+1][i][k+1]=min(dp[i+1][i][k+1],dp[i][j][k]+1);
            if(0<k)dp[i+1][j][k-1]=min(dp[i+1][j][k-1],dp[i][j][k]);
        }
    }
    
    int ans=INF;
    rep(j,0,n)ans=min(ans,dp[n][j][0]+j);
    cout<<ans<<endl;
    
    
    
    
    
    
    
    return 0;
}

Submission Info

Submission Time
Task B - 天下一魔力発電
User chocopuu
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1355 Byte
Status AC
Exec Time 6 ms
Memory 8320 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 1 ms 384 KB
01_sample_02 AC 1 ms 256 KB
01_sample_03 AC 1 ms 384 KB
02_manual_01 AC 1 ms 256 KB
02_manual_02 AC 1 ms 384 KB
02_manual_03 AC 1 ms 384 KB
10_random_00 AC 2 ms 3328 KB
10_random_01 AC 1 ms 384 KB
10_random_02 AC 2 ms 3200 KB
10_random_03 AC 3 ms 5888 KB
10_random_04 AC 1 ms 384 KB
10_random_05 AC 1 ms 768 KB
10_random_06 AC 2 ms 3328 KB
10_random_07 AC 4 ms 7808 KB
10_random_08 AC 2 ms 5760 KB
10_random_09 AC 1 ms 768 KB
10_random_10 AC 1 ms 640 KB
10_random_11 AC 1 ms 256 KB
10_random_12 AC 4 ms 6528 KB
10_random_13 AC 4 ms 6784 KB
10_random_14 AC 1 ms 640 KB
10_random_15 AC 1 ms 768 KB
10_random_16 AC 5 ms 7552 KB
10_random_17 AC 4 ms 7168 KB
10_random_18 AC 4 ms 7552 KB
10_random_19 AC 4 ms 7296 KB
20_max_00 AC 5 ms 8320 KB
20_max_01 AC 5 ms 8320 KB
20_max_02 AC 5 ms 8320 KB
20_max_03 AC 6 ms 8320 KB
20_max_04 AC 6 ms 8320 KB
20_max_05 AC 5 ms 8320 KB