# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1117790 | 2024-11-24T08:27:01 Z | vjudge1 | Match (CEOI16_match) | C++17 | 368 ms | 504 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 KB | Output is correct |
4 | Incorrect | 368 ms | 504 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 KB | Output is correct |
4 | Incorrect | 368 ms | 504 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |