# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
346237 |
2021-01-09T07:45:59 Z |
shrek12357 |
Match (CEOI16_match) |
C++14 |
|
2000 ms |
808 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
vector<char> stk;
string ans;
for (int i = 0; i < n; i++) {
if (stk.empty() || stk.back() != s[i]) {
stk.push_back(s[i]);
ans.push_back('(');
}
else {
vector<char> stk_cp = stk;
stk_cp.push_back(s[i]);
for (int j = i + 1; j < n; j++) {
if (stk_cp.empty() || stk_cp.back() != s[j]) {
stk_cp.push_back(s[j]);
}
else {
stk_cp.pop_back();
}
}
if (stk_cp.empty()) {
stk.push_back(s[i]);
ans.push_back('(');
}
else {
stk.pop_back();
ans.push_back(')');
}
}
}
if (stk.empty()) {
cout << ans << "\n";
}
else {
cout << "-1\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
4 ms |
364 KB |
Output is correct |
8 |
Correct |
43 ms |
364 KB |
Output is correct |
9 |
Correct |
45 ms |
492 KB |
Output is correct |
10 |
Correct |
38 ms |
492 KB |
Output is correct |
11 |
Correct |
39 ms |
492 KB |
Output is correct |
12 |
Execution timed out |
2064 ms |
808 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |