# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
259396 | 2020-08-07T18:03:22 Z | doowey | 괄호 문자열 (CEOI16_match) | C++14 | 1 ms | 384 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int AL = 26; const int N = (int)1e5 + 10; int id[N]; int pref[N]; map<int, vector<int>> gg[AL]; char sol[N]; void compute(int l, int r){ if(l > r) return; int mask = pref[l - 1]; int vi = upper_bound(gg[id[l]][mask].begin(), gg[id[l]][mask].end(), r) - gg[id[l]][mask].begin(); vi -- ; if(vi < 0 || vi >= gg[id[l]][mask].size()) { cout << "-1\n"; exit(0); } int idx = gg[id[l]][mask][vi]; if(idx > l && idx <= r){ sol[l] = '('; sol[idx] = ')'; compute(l + 1, idx - 1); compute(idx + 1, r); } else{ cout << "-1\n"; exit(0); } } int main(){ fastIO; string t; cin >> t; char f; int n = t.size(); for(int i = 1; i <= n; i ++ ){ f = t[i - 1]; id[i] = f - 'a'; pref[i]=(pref[i-1] ^ (1 << id[i])); gg[id[i]][pref[i]].push_back(i); } compute(1, n); for(int i = 1; i <= n; i ++ ) cout << sol[i]; cout << "\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Incorrect | 1 ms | 384 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Incorrect | 1 ms | 384 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |