# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
299700 |
2020-09-15T13:20:24 Z |
Gustav |
Match (CEOI16_match) |
C++14 |
|
2000 ms |
632 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
#define debug(x) cerr << (#x) << " " << (x) << endl;
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
int n;
string s;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> s;
n = sz(s);
stack<char> st;
for(int i = 0; i < n; i++){
if(!st.empty() && st.top() == s[i]) st.pop();
else st.push(s[i]);
}
if(!st.empty()){
cout << "-1\n";
return 0;
}
string ans = "";
for(int i = 0; i < n; i++){
if(!st.empty() && st.top() == s[i]){
stack<char> t = st;
t.push(s[i]);
for(int j = i+1; j < n; j++){
if(!t.empty() && t.top() == s[j]) t.pop();
else t.push(s[j]);
}
if(t.empty()){
st.push(s[i]);
ans.push_back('(');
}
else{
st.pop();
ans.push_back(')');
}
}
else{
st.push(s[i]);
ans.push_back('(');
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
9 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
9 ms |
384 KB |
Output is correct |
8 |
Correct |
101 ms |
404 KB |
Output is correct |
9 |
Correct |
93 ms |
384 KB |
Output is correct |
10 |
Correct |
65 ms |
384 KB |
Output is correct |
11 |
Correct |
48 ms |
384 KB |
Output is correct |
12 |
Execution timed out |
2019 ms |
632 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |