# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
63051 |
2018-07-31T12:54:37 Z |
khohko |
Match (CEOI16_match) |
C++17 |
|
2 ms |
376 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define ARRS ((ll)(2e6+500))
#define MAX ((ll)(1e9+100))
#define MOD ((ll)1e9+7)
#define mi(a,b) a=min((a),(b))
ll n,m,k,p,l,r,q;
ll c[400];
int main(){
#ifdef KHOKHO
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
string s;
cin>>s;
for(int i=0; i<s.size(); i++){
c[s[i]]++;
}
for(int i='a'; i<'z'; i++){
// cout<<(char)i<<" "<<c[i]<<endl;
if(c[i]&1){
cout<<-1;
return 0;
}
else c[i]/=2;
}
string pas;
for(int i=0; i<s.size(); i++){
if(c[s[i]])pas+="(",c[s[i]]--;
else pas+=")";
}
// cout<<pas<<endl;
stack<ll> sk;
for(int i=0; i<s.size(); i++){
if(pas[i]=='(')sk.push(i);
else if(s[i]!=s[sk.top()]){
cout<<-1;
return 0;
}
else
sk.pop();
}
cout<<pas;
}
Compilation message
match.cpp: In function 'int main()':
match.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<s.size(); i++){
~^~~~~~~~~
match.cpp:24:9: warning: array subscript has type 'char' [-Wchar-subscripts]
c[s[i]]++;
^
match.cpp:35:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<s.size(); i++){
~^~~~~~~~~
match.cpp:36:12: warning: array subscript has type 'char' [-Wchar-subscripts]
if(c[s[i]])pas+="(",c[s[i]]--;
^
match.cpp:36:29: warning: array subscript has type 'char' [-Wchar-subscripts]
if(c[s[i]])pas+="(",c[s[i]]--;
^
match.cpp:41:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<s.size(); i++){
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |