# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
126409 |
2019-07-07T15:46:13 Z |
johutha |
Match (CEOI16_match) |
C++14 |
|
2000 ms |
1208 KB |
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#define int int64_t
using namespace std;
struct brackseq
{
string s;
int n;
bool poss(int fr, vector<int> stack)
{
stack.push_back(fr);
fr++;
for (int i = fr; i < n; i++)
{
if (stack.size() == 0 || s[i] != s[stack.back()])
{
stack.push_back(i);
}
else
{
stack.pop_back();
}
}
return stack.size() == 0;
}
string calc()
{
vector<int> stack;
string seq;
for (int i = 0; i < n; i++)
{
if (poss(i, stack))
{
seq.push_back('(');
stack.push_back(i);
}
else
{
if (stack.size() == 0) return "-1";
seq.push_back(')');
stack.pop_back();
}
}
if (stack.size() > 0) return "-1";
return seq;
}
};
signed main()
{
brackseq bs;
cin >> bs.s;
bs.n = bs.s.size();
cout << bs.calc();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
9 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
9 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
9 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
9 ms |
376 KB |
Output is correct |
8 |
Correct |
106 ms |
504 KB |
Output is correct |
9 |
Correct |
130 ms |
376 KB |
Output is correct |
10 |
Correct |
94 ms |
476 KB |
Output is correct |
11 |
Correct |
93 ms |
504 KB |
Output is correct |
12 |
Execution timed out |
2069 ms |
1208 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |