Submission #2457249


Source Code Expand

#include <iostream>
#include <string>
#include <cstring>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

using ll = long long;

std::string S;
ll ans = 1<<30;
bool dp[110][110][110];

void dfs( int i, ll last, ll cnt, ll diff )
{
  if( diff < 0 )
    return;

  if( dp[last][cnt][diff] )
    return;

  if( i == S.size() )
  {
    if( !diff )
      ans = std::min( ans, cnt+last );

    return;
  }

  dfs( i+1, last, cnt, diff+(S[i]=='('?1:-1) );

  dfs( i+1, i, cnt+1, diff+(S[i]=='('?-1:1) );

  dp[last][cnt][diff] = true;

  return;
}

int main()
{
  std::cin >> S;

  dfs( 0, 0, 0, 0 );

  std::cout << ans << std::endl;

  return 0;
}

Submission Info

Submission Time
Task B - 天下一魔力発電
User As_sqr
Language C++14 (GCC 5.4.1)
Score 0
Code Size 714 Byte
Status WA
Exec Time 14 ms
Memory 1152 KB

Judge Result

Set Name All
Score / Max Score 0 / 400
Status
AC × 29
WA × 3
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 256 KB
01_sample_02 AC 1 ms 256 KB
01_sample_03 AC 1 ms 256 KB
02_manual_01 AC 1 ms 256 KB
02_manual_02 AC 1 ms 256 KB
02_manual_03 AC 1 ms 256 KB
10_random_00 AC 1 ms 512 KB
10_random_01 AC 1 ms 256 KB
10_random_02 AC 1 ms 384 KB
10_random_03 AC 2 ms 768 KB
10_random_04 AC 1 ms 256 KB
10_random_05 AC 1 ms 384 KB
10_random_06 AC 1 ms 512 KB
10_random_07 AC 5 ms 1024 KB
10_random_08 AC 2 ms 640 KB
10_random_09 AC 1 ms 384 KB
10_random_10 AC 1 ms 384 KB
10_random_11 AC 1 ms 256 KB
10_random_12 AC 3 ms 896 KB
10_random_13 WA 3 ms 896 KB
10_random_14 AC 1 ms 384 KB
10_random_15 WA 1 ms 384 KB
10_random_16 WA 4 ms 1024 KB
10_random_17 AC 3 ms 896 KB
10_random_18 AC 5 ms 1024 KB
10_random_19 AC 4 ms 1024 KB
20_max_00 AC 2 ms 896 KB
20_max_01 AC 2 ms 896 KB
20_max_02 AC 3 ms 1024 KB
20_max_03 AC 3 ms 1024 KB
20_max_04 AC 14 ms 1152 KB
20_max_05 AC 14 ms 1152 KB