Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 11:25:14
Task:Dynamic duo
Sender:Proudly div 2
Submission time:2017-05-27 11:25:14
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;

int main(){
	vector<LL> counts(256);
	string s; cin >> s;
	LL n = s.size();
	LL maxcount = 0;
	for(char c : s){
		counts[c]++;
		maxcount = max(maxcount, counts[c]);
	}

	if(n % 2 == 1){
		cout << -1 << endl;
		return 0;
	}

	if(maxcount > n / 2){
		cout << -1 << endl;
		return 0;
	}

	LL printed = 0;
	for(char c = 'A'; c <= 'Z'; c++){
		while(counts[c] > 0){
			cout << c;
			printed++;
			if(printed == n/2) cout << '\n';
			counts[c]--;
		}
	}
	cout << endl;
}