Submission #90630

# Submission time Handle Problem Language Result Execution time Memory
90630 2018-12-23T07:34:06 Z jangwonyoung Match (CEOI16_match) C++14
0 / 100
2 ms 500 KB
#include<iostream>
#include<stack>
using namespace std;
string s,b;
int cnt[226];
int cur[226];
stack<char>st;
int main(){
	ios::sync_with_stdio(false);
	cin >> s;
	for(auto c:s) cnt[c]++;
	for(auto c:s){
		if(cnt[c]%2==1){
			cout << "-1\n";
			return 0;
		}
		if(cur[c]<cnt[c]/2) b+='(';
		else b+=')';
		cur[c]++;
	}
	for(int i=0; i<s.size() ;i++){
		if(b[i]=='(') st.push(s[i]);
		else if(st.top()!=s[i]){
			cout << "-1\n";
			return 0;
		}
		else st.pop();
	}
	cout << b << endl;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:11:21: warning: array subscript has type 'char' [-Wchar-subscripts]
  for(auto c:s) cnt[c]++;
                     ^
match.cpp:13:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   if(cnt[c]%2==1){
           ^
match.cpp:17:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   if(cur[c]<cnt[c]/2) b+='(';
           ^
match.cpp:17:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   if(cur[c]<cnt[c]/2) b+='(';
                  ^
match.cpp:19:8: warning: array subscript has type 'char' [-Wchar-subscripts]
   cur[c]++;
        ^
match.cpp:21: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 256 KB Output is correct
2 Incorrect 2 ms 500 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 500 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 500 KB Output isn't correct
3 Halted 0 ms 0 KB -