Submission #3402210


Source Code Expand

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int> > vvi;
typedef std::vector<ll> vll;
typedef std::vector<std::vector<ll> > vvll;
typedef std::deque<bool> db;
template<class T> using vv=std::vector<std::vector< T > >;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// cout vector
template<typename T> std::ostream& operator<<(std::ostream& s, const std::vector<T>& v) {
  int len=v.size();s<<"\n";rep(i,len){s<<v[i];if(i<len-1){s << "\t";}}s<<"\n";return s; }
// cout 2-dimentional vector
template<typename T> std::ostream& operator<<(std::ostream& s, const std::vector<std::vector<T> >& vv) {
  int len=vv.size();rep(i,len){s<<vv[i];} return s; }
// cout deque
template<typename T> std::ostream& operator<<(std::ostream& s, const std::deque<T>& v) {
  int len=v.size();s<<"\n";rep(i,len){s<<v[i];if(i<len-1){s << "\t";}}s<<"\n";return s; }
// cout 2-dimentional deque
template<typename T> std::ostream& operator<<(std::ostream& s, const std::deque<std::deque<T> >& vv) {
  int len=vv.size();rep(i,len){s<<vv[i];} return s; }
// cout set<cout-able>
template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& v) {
  s<<"\n";for(auto elm : v){s<<elm<<"\t";}s<<"\n";return s; }

inline void scan(int&a){scanf("%d",&a);}
inline void scan(int&a,int&b){scanf("%d%d",&a,&b);}
inline void scan(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void scan(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void scan(std::vector<int>&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::vector<std::vector<int> >&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void scan(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void scan(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void scan(std::vector<ll>&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::vector<std::vector<ll> >&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(std::vector<char>&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::vector<std::vector<char> >&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}

inline void print(int a){printf("%d\n",a);}
inline void print(int a,int b){printf("%d %d\n",a,b);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(ll a,ll b){printf("%lld %lld\n",a,b);}
inline void print(std::string s){std::cout << s << "\n";}
inline void print_yn(bool flg){if(flg){printf("Yes\n");}else{printf("No\n");}}

using namespace std;

int main() {
  string s;
  scan(s);
  int n = s.length();
  auto dp = make_v<bool>(n+1, n+1, n+1, n+1);
  dp[0][0][0][0] = true;
  rep (i, n) {
    char c = s[i];
    rep (j, n+1) {
      rep (k, n) {
        rep (l, n) {
          if (dp[i][j][k][l]) {
            if (c == '(') {
              dp[i+1][j][k][l+1] = true;
              if (l > 0) {
                dp[i+1][i][k+1][l-1] = true;
              }
            } else {
              dp[i+1][i][k+1][l+1] = true;
              if (l > 0) {
                dp[i+1][j][k][l-1] = true;
              }
            } 
          }
        }
      }
    }
  }
  int ans = 9999;
  rep (j, n+1) {
    rep (k, n+1) {
      if (dp[n][j][k][0]) {
        ans = min(ans, j + k);
      }
    }
  }
  print(ans);
  return 0;
}

Submission Info

Submission Time
Task B - 天下一魔力発電
User tspcx
Language C++14 (Clang 3.8.0)
Score 400
Code Size 4406 Byte
Status AC
Exec Time 219 ms
Memory 59520 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 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 384 KB
02_manual_03 AC 1 ms 256 KB
10_random_00 AC 12 ms 4736 KB
10_random_01 AC 1 ms 384 KB
10_random_02 AC 9 ms 3584 KB
10_random_03 AC 61 ms 20224 KB
10_random_04 AC 1 ms 384 KB
10_random_05 AC 3 ms 1024 KB
10_random_06 AC 12 ms 4736 KB
10_random_07 AC 175 ms 47872 KB
10_random_08 AC 37 ms 13056 KB
10_random_09 AC 3 ms 1024 KB
10_random_10 AC 2 ms 768 KB
10_random_11 AC 1 ms 256 KB
10_random_12 AC 109 ms 32128 KB
10_random_13 AC 117 ms 34432 KB
10_random_14 AC 2 ms 640 KB
10_random_15 AC 2 ms 1024 KB
10_random_16 AC 162 ms 45056 KB
10_random_17 AC 139 ms 39552 KB
10_random_18 AC 162 ms 45056 KB
10_random_19 AC 150 ms 42240 KB
20_max_00 AC 202 ms 57472 KB
20_max_01 AC 200 ms 57472 KB
20_max_02 AC 205 ms 57472 KB
20_max_03 AC 206 ms 57472 KB
20_max_04 AC 219 ms 59520 KB
20_max_05 AC 219 ms 57472 KB