# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1117651 |
2024-11-24T07:06:09 Z |
vjudge1 |
Match (CEOI16_match) |
C++17 |
|
1 ms |
336 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F3F3F3F3F
const int MXN = 3e6 + 5;
const int mod = 998244353;
int n;
string s, res;
vector<int> st;
int fl[26], fcur[26];
void fix(int ind)
{
fcur[s[ind] - 'a'] -= 2;
res[ind] = ')';
while (!st.empty() && s[st.back()] != s[ind])
{
int nw = st.back();
st.pop_back();
fix(nw);
}
if (st.empty())
{
cout << -1 << '\n';
exit(0);
}
st.pop_back();
}
void _()
{
cin >> s;
n = s.length();
if (n & 1)
{
cout << -1 << '\n';
return;
}
for (char &ch : s) fl[ch - 'a']++;
res = s;
for (int i = 0; i < n; i++)
{
fcur[s[i] - 'a']++, fl[s[i] - 'a']--;
if (fl[s[i] - 'a'] < fcur[s[i] - 'a']) fix(i);
else res[i] = '(', st.push_back(i);
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) _();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |