Submission #3389718
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 > >;
// 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();
int ans = 99999;
rep (i, n) {
int depth = 0;
bool ok = true;
for (int j = n-1; j > i; --j) {
if (s[j] == ')') {
depth += 1;
} else {
depth -= 1;
if (depth < 0) {
ok = false;
break;
}
}
}
if (!ok) {
continue;
}
if (depth > i+1) {
continue;
}
int aim = depth;
depth = 0;
rep (j, i+1) {
if (s[i] == '(') {
depth += 1;
} else {
depth -= 1;
}
}
int dif = aim - depth;
int cnt = 0;
depth = 0;
if (dif >= 0) {
rep (j, i+1) {
if (s[j] == ')') {
dif -= 2;
cnt += 1;
}
if (dif == 0) {
break;
}
}
} else {
dif *= (-1);
rep (j, i+1) {
if (s[j] == ')') {
if (depth == 0) {
dif += 2;
cnt += 1;
depth += 1;
} else {
depth -= 1;
}
} else if (s[j] == '(') {
if (depth == 0) {
depth += 1;
} else {
dif -= 2;
cnt += 1;
depth -= 1;
}
}
if (dif == 0) {
break;
}
}
}
ans = min(ans, cnt + i);
}
print(ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - 天下一魔力発電 |
User |
tspcx |
Language |
C++14 (Clang 3.8.0) |
Score |
0 |
Code Size |
4795 Byte |
Status |
WA |
Exec Time |
1 ms |
Memory |
256 KB |
Judge Result
Set Name |
All |
Score / Max Score |
0 / 400 |
Status |
|
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 |
WA |
1 ms |
256 KB |
10_random_00 |
WA |
1 ms |
256 KB |
10_random_01 |
AC |
1 ms |
256 KB |
10_random_02 |
WA |
1 ms |
256 KB |
10_random_03 |
WA |
1 ms |
256 KB |
10_random_04 |
WA |
1 ms |
256 KB |
10_random_05 |
AC |
1 ms |
256 KB |
10_random_06 |
WA |
1 ms |
256 KB |
10_random_07 |
WA |
1 ms |
256 KB |
10_random_08 |
WA |
1 ms |
256 KB |
10_random_09 |
WA |
1 ms |
256 KB |
10_random_10 |
WA |
1 ms |
256 KB |
10_random_11 |
AC |
1 ms |
256 KB |
10_random_12 |
WA |
1 ms |
256 KB |
10_random_13 |
WA |
1 ms |
256 KB |
10_random_14 |
WA |
1 ms |
256 KB |
10_random_15 |
AC |
1 ms |
256 KB |
10_random_16 |
WA |
1 ms |
256 KB |
10_random_17 |
WA |
1 ms |
256 KB |
10_random_18 |
WA |
1 ms |
256 KB |
10_random_19 |
WA |
1 ms |
256 KB |
20_max_00 |
AC |
1 ms |
256 KB |
20_max_01 |
AC |
1 ms |
256 KB |
20_max_02 |
AC |
1 ms |
256 KB |
20_max_03 |
AC |
1 ms |
256 KB |
20_max_04 |
AC |
1 ms |
256 KB |
20_max_05 |
WA |
1 ms |
256 KB |