# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
609464 |
2022-07-27T16:01:26 Z |
Vanilla |
Match (CEOI16_match) |
C++17 |
|
2000 ms |
540 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e3 + 2;
string rs;
string s;
int n;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> s;
n = s.size();
rs = string(n, '0');
stack <char> st;
for (int i = 0; i < n; i++){
auto check = [&, st] () mutable -> bool {
st.push(s[i]);
for (int j = i + 1; j < n; j++){
if (!st.empty() && s[j] == st.top()) st.pop();
else st.push(s[j]);
}
return st.empty();
};
if (check()) {
rs[i] = '(';
st.push(s[i]);
}
else {
rs[i] = ')';
if (!st.empty() && st.top() == s[i]) st.pop();
else {
cout << "-1\n";
return 0;
}
}
}
if (st.empty()) cout << rs;
else cout << "-1";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
212 KB |
Output is correct |
7 |
Correct |
7 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
212 KB |
Output is correct |
7 |
Correct |
7 ms |
212 KB |
Output is correct |
8 |
Correct |
108 ms |
320 KB |
Output is correct |
9 |
Correct |
102 ms |
340 KB |
Output is correct |
10 |
Correct |
96 ms |
340 KB |
Output is correct |
11 |
Correct |
93 ms |
340 KB |
Output is correct |
12 |
Execution timed out |
2082 ms |
540 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |