# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
608096 |
2022-07-27T05:18:24 Z |
SeDunion |
Match (CEOI16_match) |
C++17 |
|
425 ms |
34312 KB |
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int n;
string s, ans;
const int N = 2022;
int dp[N][N];
int us[N][N];
int solve(int l, int r) {
if (l > r) return 1;
if (us[l][r]) return dp[l][r];
us[l][r] = 1;
for (int i = r ; i > l ; i -= 2) {
if (s[i] == s[l] && solve(l+1, i-1) && solve(i + 1, r)) {
return dp[l][r] = 1;
}
}
return dp[l][r];
}
void get(int l, int r) {
if (l > r) return;
for (int i = r ; i > l ; i -= 2) {
if (s[i] == s[l] && solve(l+1, i-1) && solve(i + 1, r)) {
ans[l] = '(';
ans[i] = ')';
get(l + 1, i - 1);
get(i + 1, r);
return;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin >> s;
n = s.size();
if (!solve(0, n-1)) {
cout << -1;
return 0;
}
ans = string(n, '-');
get(0, n - 1);
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
31 ms |
6680 KB |
Output is correct |
5 |
Correct |
5 ms |
5588 KB |
Output is correct |
6 |
Correct |
4 ms |
6416 KB |
Output is correct |
7 |
Correct |
425 ms |
19408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
31 ms |
6680 KB |
Output is correct |
5 |
Correct |
5 ms |
5588 KB |
Output is correct |
6 |
Correct |
4 ms |
6416 KB |
Output is correct |
7 |
Correct |
425 ms |
19408 KB |
Output is correct |
8 |
Runtime error |
230 ms |
34312 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |