CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Kortit
Sender:AtskaFin
Submission time:2020-09-25 22:05:23 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#2ACCEPTED0.02 s2details

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
 
using namespace std;

set<int> vectorToSet(vector<int> v) {
  set<int> s;
  for (auto i : v) s.insert(i);
  return s;
}

int t; // testit
vector<int> pakka1;
vector<int> pakka2;
set<int> s1;

int main() {
  cin >> t;
  for (int i = 0; i < t; i++) {
    pakka1.clear();
    pakka2.clear();
    s1.clear();

    int n; // korttien määrä
    cin >> n;

    pakka1.resize(n / 2);
    for (int i = 0; i < n / 2; i++) cin >> pakka1[i];
    sort(pakka1.begin(), pakka1.end());

    for (int i = 1, ii = 0; i <= n; i++) {
      if (i == pakka1[ii]) {
        ii++;
        continue;
      }

      pakka2.push_back(i);
    }

    /*
    cout << "Pakka 1\n";
    for (auto i : pakka1) {
      cout << i << " ";
    }
    cout << "\n\n";

    cout << "Pakka 2\n";
    for (auto i : pakka2) {
      cout << i << " ";
    }
    cout << "\n\n";
    */
    /*
    int points = 0;
    for (int i = n / 2 - 1; i >= 0; i--) {
      if (pakka1[i] > pakka2[i]) {
        points++;
        pakka1.pop_back();
      } else {
        pakka1.erase(pakka1.begin());
      }
    }

    cout << points << "\n";
    */

    s1 = vectorToSet(pakka1);

    int points = 0;
    for (int i = n / 2 - 1; i >= 0; i--) {
      auto it = s1.upper_bound(pakka2[i]);

      if (it != s1.end()) {
        // Löytyi
        points++;
        s1.erase(it);

      } else {
        // Ei löytynyt
        s1.erase(s1.begin());

      }
    }

    cout << points << "\n";
  }
}

Test details

Test 1

Group: 1, 2

Verdict:

input
1000
2
1
6
2 4 5
...

correct output
0
2
0
2
1
...

user output
0
2
0
2
1
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
70
56 23 58 70 2 57 27 61 47 3 42...

correct output
30
15
1
38
29
...

user output
30
15
1
38
29
...
Truncated