19232022-12-10 17:43:04KovácsHunorForma-1cpp11Runtime error 0/1002.078s4360 KiB
#include "stdio.h"
#include "stdlib.h"

void QuickSort(long long* arr, int* index, int size){
    int pivot = 0;
    for (int i = 1; i < size; i++)
    {
        if(arr[pivot] < arr[i] || (arr[pivot] == arr[i] && index[pivot] > index[i])){
            arr[pivot] ^= arr[pivot+1];
            arr[pivot+1] ^= arr[pivot];
            arr[pivot] ^= arr[pivot+1];

            index[pivot] ^= index[pivot+1];
            index[pivot+1] ^= index[pivot];
            index[pivot] ^= index[pivot+1];
            pivot++;

            if(i != pivot){
                arr[pivot-1] ^= arr[i];
                arr[i] ^= arr[pivot-1];
                arr[pivot-1] ^= arr[i];

                index[pivot-1] ^= index[i];
                index[i] ^= index[pivot-1];
                index[pivot-1] ^= index[i];
            }
        }
    }
    if(pivot > 1)        QuickSort(arr, index, pivot);
    if(pivot < size-2) QuickSort(arr + (pivot+1), index + (pivot+1), size - (pivot+1));
}

long long distance(long long a, long long b, long long c, long long t){
    return t*t*a + t*b + c;
}

int main()
{
    int n, q;
    scanf("%d", &n);
    int* arr = (int*)malloc(sizeof(int)*n*3);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d", arr + i, arr + i + n, arr + i + 2*n);
    }
    scanf("%d", &q);
    int* sol = (int*)malloc(sizeof(int)*q);
    long long* dis = (long long*)malloc(sizeof(long long)*n);
    int* index = (int*)malloc(sizeof(int)*n);

    for (int i = 0; i < q; i++)
    {
        int p, t;
        scanf("%d%d", &p, &t);


        for (int j = 0; j < n; j++)
        {
            index[j] = j+1;
        }
        for (int j = 0; j < n; j++)
        {
            dis[j] = distance(arr[j], arr[j+n], arr[j+2*n], t);
        }

        QuickSort(dis, index, n);
        sol[i] = index[p-1];
    }
    for (int i = 0; i < q; i++)
    {
        printf("%d\n", sol[i]);
    }
    free(arr);
    free(sol);
    free(dis);
    return 1;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1632 KiB
subtask20/20
2Runtime error81ms2968 KiB
3Runtime error85ms3048 KiB
4Runtime error82ms3256 KiB
5Runtime error79ms3312 KiB
6Runtime error83ms3440 KiB
7Runtime error81ms3668 KiB
8Runtime error81ms3848 KiB
9Runtime error79ms3848 KiB
subtask30/30
10Time limit exceeded2.065s2496 KiB
11Time limit exceeded2.059s2824 KiB
12Time limit exceeded2.036s2884 KiB
13Time limit exceeded2.048s2500 KiB
14Time limit exceeded2.043s2800 KiB
15Time limit exceeded2.075s2772 KiB
16Time limit exceeded2.063s2812 KiB
17Time limit exceeded2.075s2876 KiB
18Time limit exceeded2.063s2792 KiB
subtask40/50
19Time limit exceeded2.055s3368 KiB
20Time limit exceeded2.069s3392 KiB
21Time limit exceeded2.072s3488 KiB
22Time limit exceeded2.078s3360 KiB
23Time limit exceeded2.061s3480 KiB
24Time limit exceeded2.048s3496 KiB
25Time limit exceeded2.072s3536 KiB
26Time limit exceeded2.056s3728 KiB
27Time limit exceeded2.069s3840 KiB
28Time limit exceeded2.072s4036 KiB
29Time limit exceeded2.059s4360 KiB
30Time limit exceeded2.065s3880 KiB