# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1117647 |
2024-11-24T07:04:26 Z |
vjudge1 |
Match (CEOI16_match) |
C++17 |
|
1 ms |
336 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
mt19937_64 rnd(time(0));
vector<vector<ll>> ve;
vector<ll> ha, pr;
vector<char> ans;
void rec(int l, int r, int ind){
if (l > r){
return;
}
ll nl = l, nr = r;
while ((pr[ve[ind][nr]] ^ pr[ve[ind][nl] - 1]) != 0){
nr -= 2;
}
ans[ve[ind][nr]] = ')';
ans[ve[ind][nl]] = '(';
rec(nr + 1, r, ind);
rec(nl + 1, nr - 1, ind);
}
int main(){
ifstream inp("match.in");
ofstream oup("match.out");
string s;
inp>>s;
int n = s.size();
s = " " + s;
ve.resize(26), ha.assign(26, 0), pr.assign(n + 1, 0), ans.assign(n + 1, -1);
for (int i = 0; i < 26; i++){
ha[i] = rnd();
}
for (int i = 1; i <= n; i++){
pr[i] = pr[i - 1] ^ ha[s[i] - 'a'];
ve[s[i] - 'a'].push_back(i);
}
deque<int> de;
for (int i = 1; i <= n; i++){
int ch = s[i] - 'a';
if (de.size() == 0 || de.back() != ch){
de.push_back(ch);
}
else{
de.pop_back();
}
}
if (de.size() != 0){
oup<<-1;
}
else{
for (int i = 0; i < 26; i++){
rec(0, ve[i].size() - 1, i);
}
for (int i = 1; i <= n; i++){
oup<<ans[i];
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |