Submission #826535

# Submission time Handle Problem Language Result Execution time Memory
826535 2023-08-15T16:32:47 Z NK_ Match (CEOI16_match) C++17
0 / 100
0 ms 320 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pl = pair<ll, ll>;
using vl = V<ll>;
 
int main() {
	cin.tie(0)->sync_with_stdio(0);
 
	string S; cin >> S;

	vi F(26); for(auto& x : S) F[x-'a']++;

	vi H = F;
	for(int c = 0; c < 26; c++) {
		if (F[c] & 1) {
			cout << -1 << nl;
			return 0;
		}
		H[c] /= 2;
	}

	vi stk;
	string ans;
	for(int i = 0; i < sz(S); i++) {
		int c = S[i] - 'a';

		if (F[c] > H[c]) ans += "(", stk.pb(c);
		else {
			ans += ")";
			if (stk.back() != c) {
				cout << -1 << nl;
				return 0;
			}
			stk.pop_back();
		}
		F[c]--;
	}

	if (sz(stk)) cout << -1 << nl;
	else cout << ans << nl;

    return 0;
}			
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -