147032025-01-28 16:24:55KristófVáltakozó (75 pont)cpp17Wrong answer 6/7512ms892 KiB
#include <iostream>
#include <string>
#include <map>

using namespace std;
char nbc(map<char,int> kar,char e,char p)
{    
    if(e!=p && p!='~')
        {
        return p;
        }
for(auto x:kar)
    {

    if(x.first!=e)
        {
        return x.first;
        }
    }
    return 'Ö';

}
char sip(map<char,int>kar,int size)
{

for(auto x : kar)
    {
    //cout<<kar.size()<<"       ";
    //cout<<x.second<<" "<<size<<" sip second ";
    if((x.second*2)-1==size)
        {
        return x.first;
        }
    }
    return '~';

}



int main()
{
    string a;
    cin>>a;
    char p='~';
    int m=a.size();
    map <char,int>kar;
    for(int i=0;i<a.size();i++)
        {
        kar[a[i]]++;
        }
    char e='F';
    for(auto x:kar)
        {
        if(m-x.second>x.second)
            {
            cout<<"-1";
            return 0;
            }
        }
    while(kar.size()!=0)
        {
        if(sip(kar,m)!='~')
            {
            p=sip(kar,m);
            }
        e=nbc(kar,e,p);
        if(e=='Ö')
            {
            cout<<"-1";
            return 0;
            }
        else
            {
            cout<<e;
            kar[e]--;
            m--;
            }
        if(kar[e]==0)
            {
            kar.erase(e);
            }
        }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/75
1Wrong answer0/01ms532 KiB
2Wrong answer0/01ms508 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/32ms316 KiB
8Wrong answer0/37ms720 KiB
9Accepted3/38ms728 KiB
10Accepted3/36ms708 KiB
11Wrong answer0/31ms316 KiB
12Wrong answer0/31ms320 KiB
13Wrong answer0/31ms316 KiB
14Wrong answer0/31ms316 KiB
15Wrong answer0/312ms736 KiB
16Wrong answer0/312ms680 KiB
17Wrong answer0/310ms772 KiB
18Wrong answer0/310ms720 KiB
19Wrong answer0/39ms708 KiB
20Wrong answer0/310ms892 KiB
21Wrong answer0/39ms708 KiB
22Wrong answer0/69ms708 KiB
23Wrong answer0/610ms708 KiB
24Wrong answer0/610ms708 KiB