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

Compiler report

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

Code

#include <stdio.h> // include before iostream for faster scanf
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <set>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <tuple>
#include <utility>
#include <iomanip>
#include <iterator>

using namespace std;
typedef long long LL;

#define printv(printVec) for (auto printVecIter : (printVec)) cout << printVecIter << " "; cout << endl;

// g++ -Wall -Wshadow -std=c++11 a.cpp && ./a.out


int main() {
	std::ios::sync_with_stdio(false);cin.tie(0);
	int t;cin>>t;
	while(t--) {
		int n;cin>>n;
		vector<int> cards(n/2);
		set<int> cees;
		for (int i =0;i<n/2;i++) {
			cin>>cards[i];
			cees.emplace(cards[i]);
		}
		sort(cards.begin(), cards.end());
		vector<int> ene;
		for (int c = 1; c <=n; c++) {
			if (!cees.count(c)) {
				ene.push_back(c);
			}
		}
		vector<bool> seen(ene.size());
		int ans = 0;
		for (int i=0; i < cards.size(); i++) {
			int j = ene.size() - 1;
			while ((j>=0 && ene[j] >= cards[i]) || seen[j]) {
				j--;
				if (j == -1) break;
			}
			if (j >= 0) {
				ans++;
				seen[j] = true;
			}
		}
		cout << ans << endl;
	}
}

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