Submission #3392614


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 dp[101][101][220];
	int N = S.size();
	S = 'a' + S;
	REP(i, 101)REP(j, 101)REP(k, 220) dp[i][j][k] = LINF;
	dp[0][0][0] = 0;
	FOR(i,1,N+1){
		FOR(j,1,N+1){
			FOR(k,-100,101){
				if (dp[i - 1][j][100 + k] == LINF) continue;
				if (S[i] == '(') {
					dp[i][j][100 + k + 1] = min(dp[i][j][101 + k + 1], dp[i - 1][j][100 + k]);
					dp[i][i][100 + k - 1] = min(dp[i][i][101 + k - 1], dp[i - 1][j][100 + k] + i - j + 1);
				}
				if (S[i] == ')') {
					dp[i][j][100 + k - 1] = min(dp[i][j][101 + k - 1], dp[i - 1][j][100 + k]);
					dp[i][i][100 + k + 1] = min(dp[i][i][101 + k + 1], dp[i - 1][j][100 + k] + i - j + 1);
				}
			}
		}
	}
	int ans = LINF;
	FOR(j, 1, N) ans = min(ans, dp[N][j][101]);
	cout << ans << endl;
	
	return 0;
}

Submission Info

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

Judge Result

Set Name All
Score / Max Score 0 / 400
Status
WA × 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 WA 8 ms 8960 KB
01_sample_02 WA 5 ms 8960 KB
01_sample_03 WA 5 ms 8960 KB
02_manual_01 WA 6 ms 8960 KB
02_manual_02 WA 6 ms 8960 KB
02_manual_03 WA 6 ms 8960 KB
10_random_00 WA 5 ms 8960 KB
10_random_01 WA 6 ms 8960 KB
10_random_02 WA 6 ms 8960 KB
10_random_03 WA 6 ms 8960 KB
10_random_04 WA 5 ms 8960 KB
10_random_05 WA 5 ms 8960 KB
10_random_06 WA 6 ms 8960 KB
10_random_07 WA 7 ms 8960 KB
10_random_08 WA 6 ms 8960 KB
10_random_09 WA 5 ms 8960 KB
10_random_10 WA 5 ms 8960 KB
10_random_11 WA 5 ms 8960 KB
10_random_12 WA 7 ms 8960 KB
10_random_13 WA 7 ms 8960 KB
10_random_14 WA 6 ms 8960 KB
10_random_15 WA 6 ms 8960 KB
10_random_16 WA 6 ms 8960 KB
10_random_17 WA 6 ms 8960 KB
10_random_18 WA 6 ms 8960 KB
10_random_19 WA 6 ms 8960 KB
20_max_00 WA 7 ms 8960 KB
20_max_01 WA 7 ms 8960 KB
20_max_02 WA 7 ms 8960 KB
20_max_03 WA 7 ms 8960 KB
20_max_04 WA 7 ms 8960 KB
20_max_05 WA 7 ms 8960 KB