Submission #3392257


Source Code Expand

#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll HMOD = (ll)1e9 + 7;
const ll LMOD = 998244353;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
const long double EPS = 1e-10;

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	string S; cin >> S;
	int N = S.size();
	int ans = 0;
	int idx = 0;

	if (S[0] == ')') {
		idx = 0;
		ans += 1;
		S[0] = '(';
	}
	if (S[N-1] == '(') {
		idx = N - 1;
		ans += 1;
		S[N-1] = ')';
	}
	
	REP(j, N) {
		int cnt = 0;
		int sum = 0;
		REP(i, N) {
			if (S[i] == '(') ++sum;
			if (S[i] == ')') --sum;
			if (sum < 0) {
				idx = max(idx, i - 1);
				sum += 2;
				cnt += 1;
			}
		}
		if(sum > 0){
			REP(i,N){
				if(S[N - 1 - i] == '('){
					S[N - 1 - i] = ')';
					idx = max(idx, i);
					ans += 1;
					break;
				}
			}
		}
		if(sum == 0){
			cout << idx + cnt + ans << endl;
			break;
		}
	}



	return 0;
}

Submission Info

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

Judge Result

Set Name All
Score / Max Score 0 / 400
Status
AC × 26
WA × 6
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 WA 1 ms 256 KB
10_random_01 AC 1 ms 256 KB
10_random_02 AC 1 ms 256 KB
10_random_03 AC 1 ms 256 KB
10_random_04 AC 1 ms 256 KB
10_random_05 AC 1 ms 256 KB
10_random_06 AC 1 ms 256 KB
10_random_07 AC 1 ms 256 KB
10_random_08 AC 1 ms 256 KB
10_random_09 AC 1 ms 256 KB
10_random_10 AC 1 ms 256 KB
10_random_11 AC 1 ms 256 KB
10_random_12 AC 1 ms 256 KB
10_random_13 WA 1 ms 256 KB
10_random_14 WA 1 ms 256 KB
10_random_15 WA 1 ms 256 KB
10_random_16 WA 1 ms 256 KB
10_random_17 AC 1 ms 256 KB
10_random_18 AC 1 ms 256 KB
10_random_19 AC 1 ms 256 KB
20_max_00 AC 1 ms 256 KB
20_max_01 WA 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 AC 1 ms 256 KB