이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
int n, a[NMAX], p[NMAX], t, chk[NMAX];
string s;
map<int, deque<int>> mp[26];
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> s; n = s.size();
for(int i = 0; i < n; i++) a[i] = s[i] - 'a';
for(int i = 0; i < n; i++){
t ^= (1 << a[i]);
p[i] = t;
mp[a[i]][t].emplace_back(i);
}
for(int i = 0; i < n; i++){
if(chk[i]) continue;
t = p[i] ^ (1 << a[i]);
if(mp[a[i]][t].empty()) {
cout << -1; return 0;
}
int j = mp[a[i]][t].back();
chk[i] = 1; chk[j] = -1;
mp[a[i]][p[i]].pop_front();
mp[a[i]][t].pop_back();
}
for(int i = 0; i < n; i++) cout << (chk[i] == 1 ? '(' : ')');
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |