10132022-02-23 13:18:24CzDaniVáltakozó (75 pont)cpp14Wrong answer 6/7521ms5004 KiB
#include <iostream>
#include <vector>
using namespace std;

int main() {
	string s, ans = "";
	cin >> s;
	int n = s.size();
	vector<int> v(123);
	for (int i = 0; i < n; i++) {
		v[s[i]]++;
	}
	for (int t = 0; t < n; t++) {
		char c = 0;
		for (int i = 97; i <= 122; i++) {
			int ez = 0, mas = 0;
			for (int j = 97; j <= 122; j++) {
				if (i == j) {
					ez = v[i];
				}
				else {
					mas += v[j];
				}
			}
			if (ez > mas) {
				c = i;
			}
		}
		if (c > 0) {
			if (t > 0 && c == v[t - 1]) {
				cout << -1;
				return 0;
			}
			ans += c;
			v[c]--;
		}
		else {
			for (int i = 97; i <= 122; i++) {
				if (v[i] > 0) {
					if (t > 0 && c == v[t - 1]) {
						cout << -1;
						return 0;
					}
					c = i;
					v[c]--;
					ans += c;
				}
			}
		}
	}
	cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base6/75
1Wrong answer0/02ms1740 KiB
2Wrong answer0/01ms1796 KiB
3Wrong answer0/31ms1848 KiB
4Wrong answer0/31ms1852 KiB
5Accepted3/31ms1860 KiB
6Wrong answer0/31ms1868 KiB
7Wrong answer0/32ms1912 KiB
8Wrong answer0/38ms2756 KiB
9Accepted3/36ms2944 KiB
10Runtime error0/321ms3164 KiB
11Wrong answer0/31ms2492 KiB
12Wrong answer0/31ms2496 KiB
13Wrong answer0/31ms2500 KiB
14Wrong answer0/31ms2500 KiB
15Wrong answer0/36ms3240 KiB
16Wrong answer0/36ms3444 KiB
17Wrong answer0/36ms3636 KiB
18Wrong answer0/36ms3832 KiB
19Wrong answer0/36ms4136 KiB
20Wrong answer0/314ms4332 KiB
21Wrong answer0/36ms4528 KiB
22Wrong answer0/66ms4744 KiB
23Wrong answer0/68ms4808 KiB
24Wrong answer0/66ms5004 KiB