# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874975 |
2023-11-18T11:24:42 Z |
_fractal |
Match (CEOI16_match) |
C++14 |
|
6 ms |
12124 KB |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define make_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set<int> si;
typedef set<ll> sll;
typedef set<pii> spii;
typedef set<pll> spll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, ll> mll;
const int N = 1e5 + 2;
const int M = 1e5;
const int inf = 2e9 + 3;
const ll INF = 1e18;
const ld pi2 = 2.0 * 3.141592653589793;
const ld pi = 3.141592653589793;
const ld eps = 1e-12;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
string s, t;
int n;
int dp[N][26];
void solve(int l, int r) {
if (l > r) return;
int ch = (s[l] - 'a');
if (dp[r][ch] <= l) return;
int p = dp[r][ch];
t[l] = '(';
t[p] = ')';
solve(l + 1, p - 1);
solve(p + 1, r);
}
int main() {
speed;
cin >> s;
n = sz(s);
t = string(n, '0');
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 26; ++j) {
dp[i][j] = -1;
}
int ch = (s[i] - 'a');
int p = (i > 0 ? dp[i - 1][ch] : -1);
for (int j = 0; j < 26; ++j) {
if (p > 0) {
if (s[p - 1] - 'a' == j)
dp[i][j] = max(dp[i][j], p - 1);
else
dp[i][j] = max(dp[i][j], dp[p - 1][j]);
}
}
dp[i][ch] = i;
}
solve(0, n - 1);
bool F = 1;
for (auto c : t) if (c == '0') F = 0;
if (!F) cout << -1 << '\n';
else cout << t << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
856 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
856 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2524 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
3 ms |
7772 KB |
Output is correct |
13 |
Correct |
4 ms |
9820 KB |
Output is correct |
14 |
Correct |
4 ms |
10208 KB |
Output is correct |
15 |
Correct |
6 ms |
10664 KB |
Output is correct |
16 |
Correct |
5 ms |
10584 KB |
Output is correct |
17 |
Correct |
5 ms |
10924 KB |
Output is correct |
18 |
Correct |
6 ms |
10588 KB |
Output is correct |
19 |
Correct |
6 ms |
11356 KB |
Output is correct |
20 |
Correct |
4 ms |
7972 KB |
Output is correct |
21 |
Correct |
6 ms |
12124 KB |
Output is correct |