# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
63056 |
2018-07-31T13:42:06 Z |
bazsi700 |
Match (CEOI16_match) |
C++14 |
|
32 ms |
508 KB |
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL
//13:45
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.length();
vector<int> cnt(260,0);
for(int i = 0; i < n; i++) {
cnt[s.at(i)]++;
}
for(int i = 'a'; i <= 'z'; i++) {
if(cnt[i]%2) {
cout << -1;
return 0;
}
}
if(n > 18) {
return 0;
}
string str = "-1";
for(int mask = 0; mask < (1<<n); mask++) {
stack<int> st;
bool good = true;
string currstr = "";
for(int i = 0; i < n; i++) {
if(mask&(1<<i)) {
st.push(i);
currstr+= '(';
} else {
currstr+= ')';
if(st.empty()) {
good = false;
break;
}
if(s.at(st.top()) != s.at(i)) {
good = false;
break;
}
st.pop();
}
}
if(!st.empty()) {
good = false;
}
if(good) {
if(str.at(0) == '-' || str > currstr) {
str = currstr;
}
}
}
cout << str;
vector<int> cnt2(260,0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
32 ms |
440 KB |
Output is correct |
3 |
Correct |
3 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
32 ms |
440 KB |
Output is correct |
3 |
Correct |
3 ms |
440 KB |
Output is correct |
4 |
Incorrect |
3 ms |
508 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
32 ms |
440 KB |
Output is correct |
3 |
Correct |
3 ms |
440 KB |
Output is correct |
4 |
Incorrect |
3 ms |
508 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |