CSES - HIIT Open 2024 - Results
Submission details
Task:Just do it
Sender:Orangutans
Submission time:2024-11-16 14:59:11 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails
#160.00 sdetails
#170.00 sdetails

Compiler report

input/code.cpp: In function 'int median(int, int, int)':
input/code.cpp:19:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   19 |     if (a >= b >= c)
      |         ~~^~~~
input/code.cpp:21:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   21 |     if (c >= b >= a)
      |         ~~^~~~
input/code.cpp:23:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   23 |     if (b >= a >= c)
      |         ~~^~~~
input/code.cpp:25:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   25 |     if (c >= a >= b)
      |         ~~^~~~
input/code.cpp:27:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   27 |     if (a >= c >=b)
      |         ~~^~~~
input/code.cpp:29:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   29...

Code

// Sort an array. Initialize with low = 0 and high = len(array)
#include <vector>
#include <string>
#include <iostream>
#include <cmath>

using namespace std;


int count = 0;

void swap(vector<int>&array, int a, int b){
    int aux = array[b];
    array[b] = a;
    array[a] = aux;
}

int median(int a, int b, int c){
    if (a >= b >= c)
        return b;
    if (c >= b >= a)
        return b;
    if (b >= a >= c)
        return a;
    if (c >= a >= b)
        return a;
    if (a >= c >=b)
        return c;
    if (b >= c >= a)
        return c;
}

void HiitSort(vector<int>& array, int low,int  high){
    if (high - low > 1)
    {
        int pivot = median(array[low], array[(low + high) / 2], array[high - 1]);

        int a = low;
        int b = high - 1;
        while (true){
            while (array[a] < pivot){
                a = a + 1;
                count++;
            }
            while (array[b] > pivot) {
                b = b - 1;
                count++;
            }
            if (a >= b)
                break;
            swap(array, a, b);
            a = a + 1;
            b = b - 1;
        }

        HiitSort(array, low, a);
        HiitSort(array, a, high);
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> array = vector<int>(n);
    for (int i = 0; i < n; ++i)
        cin >> array[i];
    HiitSort(array, 0, n);

    cout << count << endl;
    if (count >= (n *n)/4)
        cout << "YES"<<endl;
    else 
        cout <<"NO" << endl;
}

Test details

Test 1

Verdict:

input
2

correct output
1 2

user output
0
NO

Test 2

Verdict:

input
3

correct output
1 2 3

user output
0
NO

Test 3

Verdict:

input
4

correct output
1 2 3 4

user output
0
NO

Test 4

Verdict:

input
5

correct output
1 2 4 3 5

user output
1
NO

Test 5

Verdict:

input
6

correct output
1 2 3 5 4 6

user output
1
NO

Test 6

Verdict:

input
7

correct output
1 2 4 6 5 3 7

user output
2
NO

Test 7

Verdict:

input
8

correct output
1 2 3 5 7 6 4 8

user output
1
NO

Test 8

Verdict:

input
9

correct output
1 2 4 6 8 3 7 5 9

user output
2
NO

Test 9

Verdict:

input
10

correct output
1 2 3 5 7 9 4 8 6 10

user output
4
NO

Test 10

Verdict:

input
99

correct output
1 2 4 6 8 10 12 14 16 18 20 22...

user output
536
NO

Test 11

Verdict:

input
100

correct output
1 2 3 5 7 9 11 13 15 17 19 21 ...

user output
558
NO

Test 12

Verdict:

input
101

correct output
1 2 4 6 8 10 12 14 16 18 20 22...

user output
565
NO

Test 13

Verdict:

input
300

correct output
1 2 3 5 7 9 11 13 15 17 19 21 ...

user output
5035
NO

Test 14

Verdict:

input
500

correct output
1 2 3 5 7 9 11 13 15 17 19 21 ...

user output
13961
NO

Test 15

Verdict:

input
998

correct output
1 2 3 5 7 9 11 13 15 17 19 21 ...

user output
55361
NO

Test 16

Verdict:

input
999

correct output
1 2 4 6 8 10 12 14 16 18 20 22...

user output
55424
NO

Test 17

Verdict:

input
1000

correct output
1 2 3 5 7 9 11 13 15 17 19 21 ...

user output
55770
NO