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

Code

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
int main()
{

	int tests, n;
	std::cin >> tests;
	std::array<int, 101> own;
	std::array<int, 101> opponent;

	std::vector<int> input;
	std::vector<int> results;
	for (int t = 0; t < tests; t++)
	{
		std::cin >> n;
		int x = n / 2;
		int nextCard = 1;
		int oppIdx = 0;
		int ownIdx = 0;
		input.clear();
		for (int i = 0; i < x; i++)
		{
			int card;
			std::cin >> card;
			input.emplace_back(card);
		}
		std::sort(input.begin(), input.end());
		for (int card : input)
		{

			while (card > nextCard)
			{
				opponent[oppIdx++] = nextCard++;
			}
			own[ownIdx++] = nextCard++;
		}
		while (oppIdx < x)
		{
			opponent[oppIdx++] = nextCard++;
		}

		/*
		for (int p = 0; p < x; p++)
			std::cout << "Own: " << own[p] << std::endl;
		for (int p = 0; p < x; p++)
			std::cout << "Opp: " << opponent[p] << std::endl;
		*/

		int playedBig = 0;
		int playedSmall = 0;
		int won = 0;
		for (int i = 0; i < x; i++) 
		{
			int oc = opponent[x - 1 - i];
			int big = own[x - 1 - playedBig];
			if (big > oc) 
			{
				won++;
				playedBig++;
			}
			else 
			{
				if (own[playedSmall++] > oc) 
				{
					won++;
				}
			}
		}
		results.emplace_back(won);
	}
	for (int w : results) 
	{
		std::cout << w << "\n";
	}
	return 0;
}


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
...

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
...