CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Kortit
Sender:Tegu
Submission time:2020-09-27 14:15:49 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED23
#2ACCEPTED77
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.02 s2details

Code

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>


size_t choose_card(int other, std::vector<int> own_cards) {
    auto it = std::upper_bound(
            own_cards.begin(),
            own_cards.end(),
            other
            );
    if (it != own_cards.end()) {
        return it - own_cards.begin();
    } else {
        return 0;
    }
}


std::vector<int> missing_cards(std::vector<int> cards) {
    int n = cards.size() * 2;
    size_t pos = 0;
    std::vector<int> other_cards;
    other_cards.reserve(n / 2);
    for (int i = 1; i <= n; ++i) {
        if (i != cards[pos]) {
            other_cards.push_back(i);
        } else {
            ++pos;
        }
    }
    return other_cards;
}


std::vector<int> read_cards(int count) {
    std::vector<int> cards(count);
    for (int i = 0; i < count; ++i) {
        std::cin >> cards[i];
        //std::cerr << cards[i] << " ";
    }
    //std::cerr << std::endl;
    std::sort(cards.begin(), cards.end());
    return cards;
}


void perform_test() {
    int n = 0;
    int score = 0;
    std::cin >> n;
    std::vector<int> own_cards = read_cards(n / 2);
    std::vector<int> other_cards = missing_cards(own_cards);
    for (auto it = other_cards.rbegin(); it != other_cards.rend(); ++it) {
        int other_card = *it;
        //std::cerr << "<" << other_card << std::endl;
        size_t card_i = choose_card(other_card, own_cards);
        assert(card_i < own_cards.size());
        int card = own_cards[card_i];
        //std::cerr << ">" << card << std::endl;
        own_cards.erase(own_cards.begin() + card_i);

        if (card > other_card) {
            ++score;
        }
    }
    std::cout << score << std::endl;
}


int main() {
    int t = 0;
    std::cin >> t;
    for (int i = 0; i < t; ++i) {
        perform_test();
    }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

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