| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1117790 | vjudge1 | 괄호 문자열 (CEOI16_match) | C++17 | 368 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 1e5 + 123; /// mind this
const int MAX = 2e6 + 123;
const int BS = 61;
const ll inf = 1e17;
const int mod = 998244353;
void solve(){
string s;
cin >> s;
ll n = s.size(), i, j, k;
ll cost[2] = {1, -1};
string ans;
for(i = 0; i < (1 << n); i++){
bool valid = true;
ll res = 0;
for(j = n - 1; j >= 0; j--){
if(i & (1 << j)){
res --;
}
else{
res ++;
}
if(res < 0){
valid = false;
break;
}
}
if(res != 0){valid = false;}
if(!valid){continue;}
bool ok = 1;
for(j = n - 1; j >= 0; j--){
res = 0;
valid = true;
if((i & (1 << j))){continue;}
for(k = j; k >= 0; k--){
if(i & (1 << k)){
res --;
}
else{
res ++;
}
if(res < 1){
if((res == 0) && (i & (1 << k))){
ok &= (s[n - j - 1] == s[n - k - 1]);
if(!ok){
break;
}
}
valid = false;
break;
}
}
if(!ok){break;}
}
if(!ok){continue;}
break;
}
if(i == (1 << n)){
cout << -1 << endl;
return ;
}
// cout << i << endl;
for(j = n - 1; j >= 0; j--){
if(i & (1 << j)){
ans += ')';
}
else{
ans += '(';
}
}
cout << ans << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
10 10
10 10 10 10 10 10 10 10 10 10
1 2
2 4
5 2
6 3
3 1
6 7
9 7
8 6
8 10
*/
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
