CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Kortit
Sender:JuustoPala
Submission time:2020-09-25 18:22:31 +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 <bits/stdc++.h>

using namespace std;

int main()
{
  int t, n;
  cin >> t;

  for (int i = 0; i < t; i++)
  {
    cin >> n;
    vector<bool> isown(n + 1);
    vector<bool> used(n + 1);
    int points = 0;

    for (int j = 0; j < n / 2; j++)
    {
      int x;
      cin >> x;
      isown[x] = true;
    }

    for (int j = 1; j <= n; j++)
    {

      if (!isown[j])
      {

        int minx = 9999999;
        for (int r = 1; r <= n; r++)
        {
          if (!used[r] && isown[r] && r > j)
          {
            if (minx - j > r - j)
            {
              minx = r;
            }
          }
        }

        if (minx != 9999999)
        {
          used[minx] = true;
          points++;
        }
      }
    }
    cout << points << "\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
...
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