# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
198269 | 2020-01-25T09:27:35 Z | Atalasion | 괄호 문자열 (CEOI16_match) | C++14 | 7 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 = 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 7 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 7 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 7 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |