# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198269 | Atalasion | Match (CEOI16_match) | C++14 | 7 ms | 376 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.
//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 20 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;
string s;
int val[N][N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> s;
int n = s.size();
for (int mask = 0; mask < (1 << n); mask++){
string res = "";
memset(val, 0, sizeof val);
for (int i = n - 1; i >= 0; i--){
if (mask & (1 << i)) res += ")";
else res += "(";
}
bool f = 0;
int cnt = 0;
for (int i = 0; i < s.size(); i++){
if (res[i] == '(') cnt++;
else cnt--;
if (cnt < 0) f = 1;
}
// if (mask == 11) cout << res << ' ' << f << '\n';
if (cnt != 0) f = 1;
for (int i = 0; i < s.size(); i++){
if (res[i] == ')') continue;
for (int j = i + 1; j < s.size(); j++){
if (res[j] == ')'){
if (j == i + 1 || val[i + 1][j - 1]){
if (s[i] != s[j]) f = 1;
}
}
}
}
if (!f) return cout << res, 0;
}
cout << -1;
return 0;
}
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... |