# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
239471 |
2020-06-15T18:39:41 Z |
arvindr9 |
Match (CEOI16_match) |
C++14 |
|
5 ms |
384 KB |
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
// #include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;
string st;
int n;
const int maxn = 1e5 + 5;
vector<int> char_inds[27];
char ans[maxn];
set<int> right_inds;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
// freopen("match.in", "r", stdin);
// freopen("match.out", "w", stdout);
cin >> st;
n = st.size();
for (int i = 0; i < n; i++) {
char_inds[st[i] - 'a'].push_back(i);
}
right_inds.insert(n);
bool possible = true;
for (int i = 0; i < n; i++) {
if (right_inds.count(i)) {
right_inds.erase(i);
continue;
}
ans[i] = '(';
int char_val = st[i] - 'a';
int next_right_index = lb(char_inds[char_val].begin(), char_inds[char_val].end(), *(right_inds.ub(i))) - char_inds[char_val].begin() - 1;
if (next_right_index < 0) {
possible = false;
break;
}
int char_ind = char_inds[char_val][next_right_index];
if (char_ind > i) {
right_inds.insert(char_ind);
ans[char_ind] = ')';
} else {
possible = false;
break;
}
}
if (!possible) {
cout << -1 << "\n";
} else {
for (int i = 0; i < n; i++) {
cout << ans[i];
}
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |