Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define times(I, X) for (int I=0; I<X; I++)
- #ifdef DEBUG
- #define deb(X) X
- #define log(X) std::cout << X << "\n"
- #define dump(X) std::cout << __LINE__ << "L: [" << #X << "] = [" << X << "]\n"
- #else
- #define deb(X)
- #define log(X)
- #define dump(X)
- #endif
- #define fi first
- #define se second
- #define pb push_back
- using namespace std;
- using ll = long long;
- using ull = unsigned long long;
- int main() {
- #ifndef DEBUG
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- // freopen("forest.in", "r", stdin);
- // freopen(s"forest.out", "w", stdout);
- #endif
- int n;
- cin >> n;
- string s;
- cin >> s;
- int r = n / 2, l = n / 2;
- for(int i = 0; i < n; i++)
- {
- char c = s[i];
- if(c == '(')
- {
- r--;
- }
- else if(c == ')')
- {
- l--;
- }
- }
- if(n % 2 == 1 || s[0] == ')' || s[n - 1] == '(')
- {
- cout << ":(";
- return 0;
- }
- int bracket = 0;
- for(int i = 0; i < n; i++)
- {
- if(s[i] == '(')
- {
- bracket++;
- }
- else if(s[i] == ')')
- {
- if(bracket == 0)
- {
- cout << ":(";
- return 0;
- }
- else{
- bracket--;
- }
- }
- else{
- if(r > 0)
- {
- s[i] = '(';
- r--;
- bracket++;
- }
- else{
- s[i] = ')';
- l--;
- if(bracket == 0)
- {
- cout << ":(";
- return 0;
- }
- else{
- bracket--;
- }
- }
- }
- if(i != n - 1 && bracket == 0) {
- cout << ":(";
- return 0;
- }
- }
- if(bracket != 0)
- {
- cout << ":(";
- return 0;
- }
- cout << s;
- return 0;
- }
- //((?()(?)?)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement