# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198313 | 2020-01-25T14:52:26 Z | Atalasion | Match (CEOI16_match) | C++14 | 3 ms | 376 KB |
//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 = 0; i < n; i++){ if (mask & (1 << i)) res += ")"; else res += "("; } reverse(all(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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 3 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 3 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 3 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |