19242022-12-10 17:45:12KovácsHunorForma-1cpp11Time limit exceeded 20/1002.099s4144 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);
    free(index);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1328 KiB
subtask220/20
2Accepted82ms2840 KiB
3Accepted86ms3088 KiB
4Accepted82ms3292 KiB
5Accepted79ms3428 KiB
6Accepted83ms3664 KiB
7Accepted81ms3864 KiB
8Accepted81ms4044 KiB
9Accepted79ms4144 KiB
subtask30/30
10Time limit exceeded2.075s2744 KiB
11Time limit exceeded2.055s2880 KiB
12Time limit exceeded2.063s2652 KiB
13Time limit exceeded2.013s2876 KiB
14Time limit exceeded2.055s3024 KiB
15Time limit exceeded2.058s3332 KiB
16Time limit exceeded2.042s3164 KiB
17Time limit exceeded2.038s3120 KiB
18Time limit exceeded2.058s3228 KiB
subtask40/50
19Time limit exceeded2.063s3660 KiB
20Time limit exceeded2.072s3596 KiB
21Time limit exceeded2.072s3392 KiB
22Time limit exceeded2.099s3756 KiB
23Time limit exceeded2.005s3784 KiB
24Time limit exceeded2.013s4036 KiB
25Time limit exceeded2.052s4080 KiB
26Time limit exceeded2.052s3876 KiB
27Time limit exceeded2.096s3988 KiB
28Time limit exceeded2.052s3708 KiB
29Time limit exceeded2.081s3988 KiB
30Time limit exceeded2.072s3712 KiB