Submission #90638

# Submission time Handle Problem Language Result Execution time Memory
90638 2018-12-23T07:50:41 Z jangwonyoung Match (CEOI16_match) C++14
10 / 100
2 ms 520 KB
#include<iostream>
#include<stack>
#include<set>
using namespace std;
string s,b;
int n;
set<int>st[226];
stack<int>cut;
int main(){
	ios::sync_with_stdio(false);
	cin >> s;
	b=s;
	n=s.size();
	for(int i=0; i<n ;i++) st[s[i]].insert(i);
	cut.push(n);
	for(int i=0; i<n ;i++){
		if(!cut.empty() && i==cut.top()){
			b[i]=')';
			cut.pop();
			continue;
		}
		st[s[i]].erase(i);
		b[i]='(';
		auto it=st[s[i]].lower_bound(cut.top());
		if(it==st[s[i]].begin()){
			cout << "-1\n";
			return 0;
		}
		--it;
		cut.push(*it);
		st[s[i]].erase(it);
	}
	cout << b << '\n';
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:14:32: warning: array subscript has type 'char' [-Wchar-subscripts]
  for(int i=0; i<n ;i++) st[s[i]].insert(i);
                                ^
match.cpp:22:10: warning: array subscript has type 'char' [-Wchar-subscripts]
   st[s[i]].erase(i);
          ^
match.cpp:24:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   auto it=st[s[i]].lower_bound(cut.top());
                  ^
match.cpp:25:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   if(it==st[s[i]].begin()){
                 ^
match.cpp:31:10: warning: array subscript has type 'char' [-Wchar-subscripts]
   st[s[i]].erase(it);
          ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Incorrect 2 ms 520 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Incorrect 2 ms 520 KB Output isn't correct
5 Halted 0 ms 0 KB -