# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
681394 |
2023-01-13T00:23:44 Z |
vjudge1 |
Match (CEOI16_match) |
C++14 |
|
718 ms |
32360 KB |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
const int N = 2000 + 5;
const int mod = 1e9 + 7;
int f[N][N];
string s;
string t;
int n;
int dp(int l, int r)
{
if(l > r) return 1;
if((r - l + 1) & 1) return 0;
int &res = f[l][r];
if(~res) return res;
res = 0;
if(s[l] == s[r]) res |= dp(l + 1, r - 1);
for(int i = r - 1; i > l; i--)
{
if(s[l] == s[i])
res |= (dp(l + 1, i - 1) && dp(i + 1, r));
if(res) break;
}
return res;
}
void trace(int l, int r)
{
if(l > r) return;
if(s[l] == s[r])
{
t[l] = '(', t[r] = ')';
trace(l + 1, r - 1);
return;
}
for(int i = r - 1; i > l; i--) if((dp(l + 1, i - 1) && dp(i + 1, r)))
{
t[l] = '(', t[i] = ')';
trace(l + 1, i - 1);
trace(i + 1, r);
return;
}
}
void solve()
{
cin >> s;
int n = s.size();
t.resize(n);
memset(f, -1, sizeof f);
if(dp(0, n - 1))
{
trace(0, n - 1);
cout << t;
}
else cout << -1;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15956 KB |
Output is correct |
2 |
Correct |
6 ms |
16064 KB |
Output is correct |
3 |
Correct |
6 ms |
16048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15956 KB |
Output is correct |
2 |
Correct |
6 ms |
16064 KB |
Output is correct |
3 |
Correct |
6 ms |
16048 KB |
Output is correct |
4 |
Correct |
64 ms |
15956 KB |
Output is correct |
5 |
Correct |
17 ms |
15956 KB |
Output is correct |
6 |
Correct |
6 ms |
16108 KB |
Output is correct |
7 |
Correct |
718 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15956 KB |
Output is correct |
2 |
Correct |
6 ms |
16064 KB |
Output is correct |
3 |
Correct |
6 ms |
16048 KB |
Output is correct |
4 |
Correct |
64 ms |
15956 KB |
Output is correct |
5 |
Correct |
17 ms |
15956 KB |
Output is correct |
6 |
Correct |
6 ms |
16108 KB |
Output is correct |
7 |
Correct |
718 ms |
16076 KB |
Output is correct |
8 |
Runtime error |
399 ms |
32360 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |