CSES - Datatähti 2024 loppu - Results
Submission details
Task:Sukat
Sender:EeliH
Submission time:2024-01-20 14:21:53 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED37
#3ACCEPTED35
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.00 s1, 2, 3details
#6ACCEPTED0.00 s1, 2, 3details
#7ACCEPTED0.00 s1, 2, 3details
#8ACCEPTED0.00 s2, 3details
#9ACCEPTED0.00 s2, 3details
#10ACCEPTED0.01 s2, 3details
#11ACCEPTED0.00 s2, 3details
#12ACCEPTED0.00 s2, 3details
#13ACCEPTED0.00 s2, 3details
#14ACCEPTED0.00 s2, 3details
#15ACCEPTED0.88 s3details
#16ACCEPTED0.72 s3details
#17ACCEPTED0.80 s3details
#18ACCEPTED0.82 s3details
#19ACCEPTED0.86 s3details
#20ACCEPTED0.83 s3details
#21ACCEPTED0.79 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i < strlen(s); i++) {
      |                     ~~^~~~~~~~~~~
input/code.cpp:59:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<char, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0; i < res.size(); i++) {
      |                     ~~^~~~~~~~~~~~
input/code.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%s", s);
      |     ~~~~~^~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;

#define CHARS 26

priority_queue<pair<int, int>> nums;
int start[CHARS];
char s[1000000];

int main()
{
    vector<pair<char, char>> res;

    scanf("%s", s);
    for (int i = 0; i < strlen(s); i++) {
        char c = s[i];

        int a = c - 'A';
        start[a]++;
    }

    for (int i = 0; i < CHARS; i++) {
        if (start[i] > 0) {
            nums.push(make_pair(start[i], i));
        }
    }

    while (!nums.empty())
    {
        //cerr << nums.size() << endl;
        pair<int, int> a = make_pair(nums.top().first, nums.top().second);
        nums.pop();

        if (nums.empty()) {
            break;
        }

        pair<int, int> b = make_pair(nums.top().first, nums.top().second);
        nums.pop();
        b.first -= 1;
        a.first -= 1;
        res.push_back(make_pair(b.second + 'A', a.second + 'A'));

        if (b.first != 0) {
            nums.push(b);
        }

        if (a.first != 0) {
            nums.push(a);
        }
    }

    for (int i = 0; i < CHARS; i++) {
        //cerr << nums[i] << endl;
    }

    cout << res.size() << endl;

    for (int i = 0; i < res.size(); i++) {
        cout << res[i].first << res[i].second << endl;
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
QBAXGXJZJS

correct output
5
XJ
ZX
SQ
JG
...

user output
5
JX
XZ
QS
GJ
...

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
SSSSSSSSSS

correct output
0

user output
0

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
SETTSESEEE

correct output
5
ES
ET
ES
ET
...

user output
5
SE
TE
SE
TE
...

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
SSMRSSSSKR

correct output
4
SR
SR
SM
SK

user output
4
RS
RS
MS
KS

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
BIIILIIRRL

correct output
5
IR
IL
IR
IL
...

user output
5
RI
LI
RI
LI
...

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
YYGEYTDSTY

correct output
5
YT
YT
YS
YG
...

user output
5
TY
TY
SY
GY
...

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
MMMMMMMMMN

correct output
1
MN

user output
1
NM

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
XQQZJQDDJOWXDFVQUIODDJIZIQDQIW...

correct output
500
DQ
DQ
DQ
DQ
...

user output
500
QD
QD
QD
QD
...
Truncated

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
IIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

correct output
0

user output
0

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
KEOHHYHHAIHLLHEKIHKAHHHHOHEHHE...

correct output
493
HA
HA
HA
HA
...

user output
493
AH
AH
AH
AH
...
Truncated

Test 11

Group: 2, 3

Verdict: ACCEPTED

input
WNNFXQNODQFSQVQQPNLQNQNNVVNXHN...

correct output
499
NQ
NQ
NQ
NQ
...

user output
499
QN
QN
QN
QN
...
Truncated

Test 12

Group: 2, 3

Verdict: ACCEPTED

input
VGAHMMMXMMVXAAMMMOMMMXVMMMYMXT...

correct output
500
MH
MH
MH
MH
...

user output
500
HM
HM
HM
HM
...
Truncated

Test 13

Group: 2, 3

Verdict: ACCEPTED

input
KKKKUUAKKAUKKKKFKKSVKCWKKKCVOJ...

correct output
500
KI
KI
KI
KI
...

user output
500
IK
IK
IK
IK
...
Truncated

Test 14

Group: 2, 3

Verdict: ACCEPTED

input
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV...

correct output
100
VP
VP
VP
VP
...

user output
100
PV
PV
PV
PV
...
Truncated

Test 15

Group: 3

Verdict: ACCEPTED

input
FKKJJBWTSFCDEKFPOKIPWZSVKHACMC...

correct output
100000
CK
CK
CK
CK
...

user output
100000
KC
KC
KC
KC
...
Truncated

Test 16

Group: 3

Verdict: ACCEPTED

input
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

correct output
0

user output
0

Test 17

Group: 3

Verdict: ACCEPTED

input
WVKKVVADNVCVKLVYVVZVKVCTNKVLVV...

correct output
99925
VC
VC
VC
VC
...

user output
99925
CV
CV
CV
CV
...
Truncated

Test 18

Group: 3

Verdict: ACCEPTED

input
BBBBBDNXDZQXBBYBBWBSBTMADXBBVZ...

correct output
99999
BE
BE
BE
BE
...

user output
99999
EB
EB
EB
EB
...
Truncated

Test 19

Group: 3

Verdict: ACCEPTED

input
FBRDPLUMLZMLLLUFUCLEMCMULLZLFL...

correct output
100000
LU
LU
LU
LU
...

user output
100000
UL
UL
UL
UL
...
Truncated

Test 20

Group: 3

Verdict: ACCEPTED

input
UUBUBUTUJSLUVBUXTUUMUXUXTMXUXS...

correct output
100000
UX
UX
UX
UX
...

user output
100000
XU
XU
XU
XU
...
Truncated

Test 21

Group: 3

Verdict: ACCEPTED

input
PPPPPPPPPPEPPPPPPPPPPBOPPPPPPP...

correct output
20000
PB
PB
PB
PB
...

user output
20000
BP
BP
BP
BP
...
Truncated