# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
259396 | doowey | Match (CEOI16_match) | C++14 | 1 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |