CSES - HIIT Open 2017 - Results
Submission details
Task:Dynamic duo
Sender:kyy-kol
Submission time:2017-05-27 12:04:14 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.06 sdetails
#30.05 sdetails
#4ACCEPTED0.06 sdetails
#50.03 sdetails
#6ACCEPTED0.06 sdetails
#70.06 sdetails
#8ACCEPTED0.03 sdetails
#90.04 sdetails
#10ACCEPTED0.07 sdetails
#11ACCEPTED0.05 sdetails
#12ACCEPTED0.05 sdetails
#130.07 sdetails
#140.04 sdetails
#150.04 sdetails
#16ACCEPTED0.04 sdetails
#170.04 sdetails
#180.05 sdetails
#19ACCEPTED0.04 sdetails
#20ACCEPTED0.05 sdetails
#21ACCEPTED0.05 sdetails
#220.05 sdetails
#230.06 sdetails
#240.05 sdetails
#25ACCEPTED0.03 sdetails
#260.06 sdetails
#270.05 sdetails
#28ACCEPTED0.05 sdetails
#29ACCEPTED0.05 sdetails
#30ACCEPTED0.06 sdetails
#31ACCEPTED0.04 sdetails
#32ACCEPTED0.04 sdetails
#330.05 sdetails
#34ACCEPTED0.04 sdetails
#350.03 sdetails
#360.05 sdetails
#370.06 sdetails
#380.04 sdetails
#390.05 sdetails
#40ACCEPTED0.05 sdetails
#410.04 sdetails
#420.04 sdetails
#430.04 sdetails
#44ACCEPTED0.04 sdetails
#45ACCEPTED0.05 sdetails
#46ACCEPTED0.07 sdetails
#470.07 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:23:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size()/2; ++i) {
                                  ^

Code

#include <iostream>
#include <vector>

using namespace std;
int cc[26];
vector<int> ca;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if (s.size()%2) {
        cout << -1 << endl;
        return 0;
    }
    string a, b;
    for (char c : s) {
        cc[c-'A']++;
    }
    for (int ci = 0; ci < 26; ++ci) {
        if (cc[ci]) ca.push_back(ci);
    }
    for (int i = 0; i < s.size()/2; ++i) {
        if (ca.size()<2) {
            cout << -1 << endl;
            return 0;
        }
        int q = ca.back(); ca.pop_back();
        int w = ca.back(); ca.pop_back();
        a.push_back(q+'A');
        b.push_back(w+'A');
        cc[w]--; cc[q]--;
        if (cc[w]) ca.push_back(w);
        if (cc[q]) ca.push_back(q);
    }
    cout << a << endl;
    cout << b << endl;
}

Test details

Test 1

Verdict: ACCEPTED

input
BA

correct output
A
B

user output
B
A

Test 2

Verdict: ACCEPTED

input
AA

correct output
-1

user output
-1

Test 3

Verdict:

input
CAAB

correct output
AA
BC

user output
-1

Test 4

Verdict: ACCEPTED

input
BABA

correct output
AA
BB

user output
BB
AA

Test 5

Verdict:

input
BBCCAA

correct output
AAB
BCC

user output
-1

Test 6

Verdict: ACCEPTED

input
AAAB

correct output
-1

user output
-1

Test 7

Verdict:

input
BAABAC

correct output
AAA
BBC

user output
-1

Test 8

Verdict: ACCEPTED

input
ABABAB

correct output
AAA
BBB

user output
BBB
AAA

Test 9

Verdict:

input
BCBACAAB

correct output
AAAB
BBCC

user output
-1

Test 10

Verdict: ACCEPTED

input
AAAA

correct output
-1

user output
-1

Test 11

Verdict: ACCEPTED

input
AABCAA

correct output
-1

user output
-1

Test 12

Verdict: ACCEPTED

input
AAABBA

correct output
-1

user output
-1

Test 13

Verdict:

input
BBAACCAA

correct output
AAAA
BBCC

user output
-1

Test 14

Verdict:

input
ABAACBBA

correct output
AAAA
BBBC

user output
-1

Test 15

Verdict:

input
BBCCABAAAC

correct output
AAAAB
BBCCC

user output
-1

Test 16

Verdict: ACCEPTED

input
BAAABABB

correct output
AAAA
BBBB

user output
BBBB
AAAA

Test 17

Verdict:

input
CBBACABBAA

correct output
AAAAB
BBBCC

user output
-1

Test 18

Verdict:

input
BCACBAACBABC

correct output
AAAABB
BBCCCC

user output
-1

Test 19

Verdict: ACCEPTED

input
AAAABA

correct output
-1

user output
-1

Test 20

Verdict: ACCEPTED

input
BAAAACBA

correct output
-1

user output
-1

Test 21

Verdict: ACCEPTED

input
BBAAAABA

correct output
-1

user output
-1

Test 22

Verdict:

input
BAACCBABAA

correct output
AAAAA
BBBCC

user output
-1

Test 23

Verdict:

input
BABACAABAB

correct output
AAAAA
BBBBC

user output
-1

Test 24

Verdict:

input
CCAABBABCBAA

correct output
AAAAAB
BBBCCC

user output
-1

Test 25

Verdict: ACCEPTED

input
AABBAAABBB

correct output
AAAAA
BBBBB

user output
BBBBB
AAAAA

Test 26

Verdict:

input
BABAACACBBAB

correct output
AAAAAB
BBBBCC

user output
-1

Test 27

Verdict:

input
AABBBCCABCABAC

correct output
AAAAABB
BBBCCCC

user output
-1

Test 28

Verdict: ACCEPTED

input
AAAAAA

correct output
-1

user output
-1

Test 29

Verdict: ACCEPTED

input
AABACAAA

correct output
-1

user output
-1

Test 30

Verdict: ACCEPTED

input
BAAABAAA

correct output
-1

user output
-1

Test 31

Verdict: ACCEPTED

input
ABAABAACAC

correct output
-1

user output
-1

Test 32

Verdict: ACCEPTED

input
AAAABACBBA

correct output
-1

user output
-1

Test 33

Verdict:

input
BABCCBAACAAA

correct output
AAAAAA
BBBCCC

user output
-1

Test 34

Verdict: ACCEPTED

input
BBBAAAABAA

correct output
-1

user output
-1

Test 35

Verdict:

input
ABBABBAAACCA

correct output
AAAAAA
BBBBCC

user output
-1

Test 36

Verdict:

input
BCACABBACACABA

correct output
AAAAAAB
BBBCCCC

user output
-1

Test 37

Verdict:

input
BAABCBAAAABB

correct output
AAAAAA
BBBBBC

user output
-1

Test 38

Verdict:

input
ABBAACCABBCABA

correct output
AAAAAAB
BBBBCCC

user output
-1

Test 39

Verdict:

input
ABCACCBABBAACABC

correct output
AAAAAABB
BBBCCCCC

user output
-1

Test 40

Verdict: ACCEPTED

input
ABBBAAABBABA

correct output
AAAAAA
BBBBBB

user output
BBBBBB
AAAAAA

Test 41

Verdict:

input
AAACAABBCABBBB

correct output
AAAAAAB
BBBBBCC

user output
-1

Test 42

Verdict:

input
BCBBBCAABABCCAAA

correct output
AAAAAABB
BBBBCCCC

user output
-1

Test 43

Verdict:

input
BBCBAABACCCBAACACB

correct output
AAAAAABBB
BBBCCCCCC

user output
-1

Test 44

Verdict: ACCEPTED

input
BBABBABABAABAAABBAAABBBBBBAABB...

correct output
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

user output
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

Test 45

Verdict: ACCEPTED

input
AAAABABABBBBABAABBBABBBBBABBAB...

correct output
-1

user output
-1

Test 46

Verdict: ACCEPTED

input
ABBBAABAABAAABBAAAAABBBABAAAAB...

correct output
-1

user output
-1

Test 47

Verdict:

input
XOQPQRNTLADFTEQSZYBMIRXWHSQDCM...

correct output
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

user output
-1