CSES - Datatähti 2024 loppu - Results
Submission details
Task:Peli
Sender:stpn129
Submission time:2024-01-20 14:31:25 +0200
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.00 s1, 2details
#20.00 s1, 2details
#30.00 s2details
#40.00 s1, 2details
#50.00 s1, 2details
#60.00 s2details
#70.00 s2details
#80.00 s1, 2details
#90.00 s2details
#100.00 s2details

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    for (int i = 0; i < ans.size(); ++i) {
      |                    ~~^~~~~~~~~~~~

Code

#include<bits/stdc++.h>
using namespace std;
 
void init_code(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}

void solve() {
   string s;
   cin >> s;

   int n = s.size();

   vector<pair<int, int>> tmp(26);

   for (int i = 0; i < n; ++i) {
      int x = s[i] - 'A';

      tmp[x].first++;
      tmp[x].second = x;
   }

   priority_queue<pair<int, int>> pq;
   for (auto i : tmp) {
      pq.push(i);
   }

   vector<string> ans;

   while (!pq.empty()) {
      pair<int, int> a = pq.top();
      pq.pop();
      //cout << a.first << ' ' << a.second << '\n';
      
      if (pq.empty()) break;

      pair<int, int> b = pq.top();
      pq.pop();

      if (a.first == 0 || b.first == 0) break;

      string t = "";
      char x = 'A' + a.second, y = 'A' + b.second;
      t += x; t += y;

      int k = b.first;

      for (int i = 0; i < k; ++i) {
         ans.push_back(t);
      }

      pq.push({a.first - b.first, a.second});
      
   }

   cout << ans.size() << '\n';
   for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i] << '\n';
   }
}

int main() {
   init_code();
   solve();
   return 0;
}
 

Test details

Test 1

Group: 1, 2

Verdict:

input
2 1 100
1 2
1 1 0
1 2 0
2 1 0
...

correct output
YES
NO
NO
YES
NO
...

user output
0

Test 2

Group: 1, 2

Verdict:

input
50 49 100
33 34
7 8
49 50
47 48
...

correct output
NO
NO
NO
NO
NO
...

user output
0

Test 3

Group: 2

Verdict:

input
2500 2499 100000
821 822
2351 2352
752 753
832 833
...

correct output
NO
YES
YES
NO
NO
...

user output
0

Test 4

Group: 1, 2

Verdict:

input
12 12 100
9 10
2 3
1 12
1 2
...

correct output
NO
NO
NO
NO
NO
...

user output
0

Test 5

Group: 1, 2

Verdict:

input
11 11 100
10 11
7 8
1 2
5 6
...

correct output
YES
YES
YES
YES
YES
...

user output
0

Test 6

Group: 2

Verdict:

input
2500 2500 100000
1936 1937
1884 1885
751 752
831 832
...

correct output
NO
YES
YES
NO
NO
...

user output
0

Test 7

Group: 2

Verdict:

input
2499 2499 100000
821 822
2351 2352
752 753
832 833
...

correct output
YES
YES
YES
YES
YES
...

user output
0

Test 8

Group: 1, 2

Verdict:

input
50 99 100
40 47
34 50
44 47
15 16
...

correct output
YES
YES
YES
YES
YES
...

user output
0

Test 9

Group: 2

Verdict:

input
2500 4999 100000
1191 2361
251 399
1026 2300
82 1655
...

correct output
YES
YES
YES
YES
YES
...

user output
0

Test 10

Group: 2

Verdict:

input
2500 4999 100000
2023 2218
23 51
1020 1272
11 114
...

correct output
YES
YES
YES
YES
YES
...

user output
0