Submission #4643190
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2019/03/21 Problem: ABC 064 D / Link: http://abc064.contest.atcoder.jp/tasks/abc064_d ----- */
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
LL N; cin >> N;
string s; cin >> s;
int R = 0, L = 0;
FOR(i, 0, N) {
if (s[i] == '(') {
L++;
}
else { // )
if (L > 0)L--;
else R++;
}
}
string ans = string(R, '(') + s + string(L, ')');
cout << (ans) << "\n";
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Insertion |
| User |
Yang33 |
| Language |
C++14 (GCC 5.4.1) |
| Score |
400 |
| Code Size |
1408 Byte |
| Status |
AC |
| Exec Time |
2 ms |
| Memory |
256 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
s1.txt, s2.txt, s3.txt |
| All |
in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, s1.txt, s2.txt, s3.txt |
| Case Name |
Status |
Exec Time |
Memory |
| in1.txt |
AC |
2 ms |
256 KiB |
| in2.txt |
AC |
1 ms |
256 KiB |
| in3.txt |
AC |
1 ms |
256 KiB |
| in4.txt |
AC |
1 ms |
256 KiB |
| in5.txt |
AC |
1 ms |
256 KiB |
| in6.txt |
AC |
1 ms |
256 KiB |
| in7.txt |
AC |
1 ms |
256 KiB |
| in8.txt |
AC |
1 ms |
256 KiB |
| in9.txt |
AC |
1 ms |
256 KiB |
| s1.txt |
AC |
1 ms |
256 KiB |
| s2.txt |
AC |
1 ms |
256 KiB |
| s3.txt |
AC |
1 ms |
256 KiB |