1922 | 2022-12-10 17:42:26 | KovácsHunor | Forma-1 | cpp17 | Runtime error 0/100 | 2.099s | 4292 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 3ms | 1432 KiB | ||||
subtask2 | 0/20 | ||||||
2 | Runtime error | 82ms | 2844 KiB | ||||
3 | Runtime error | 85ms | 3044 KiB | ||||
4 | Runtime error | 82ms | 3104 KiB | ||||
5 | Runtime error | 79ms | 3328 KiB | ||||
6 | Runtime error | 83ms | 3536 KiB | ||||
7 | Runtime error | 81ms | 3752 KiB | ||||
8 | Runtime error | 81ms | 3748 KiB | ||||
9 | Runtime error | 79ms | 3972 KiB | ||||
subtask3 | 0/30 | ||||||
10 | Time limit exceeded | 2.059s | 2728 KiB | ||||
11 | Time limit exceeded | 2.072s | 2732 KiB | ||||
12 | Time limit exceeded | 2.059s | 2712 KiB | ||||
13 | Time limit exceeded | 2.072s | 2700 KiB | ||||
14 | Time limit exceeded | 2.055s | 3188 KiB | ||||
15 | Time limit exceeded | 2.063s | 3172 KiB | ||||
16 | Time limit exceeded | 2.072s | 3308 KiB | ||||
17 | Time limit exceeded | 2.075s | 3568 KiB | ||||
18 | Time limit exceeded | 2.061s | 3276 KiB | ||||
subtask4 | 0/50 | ||||||
19 | Time limit exceeded | 2.099s | 3364 KiB | ||||
20 | Time limit exceeded | 2.075s | 3636 KiB | ||||
21 | Time limit exceeded | 2.069s | 3888 KiB | ||||
22 | Time limit exceeded | 2.052s | 3928 KiB | ||||
23 | Time limit exceeded | 2.056s | 4132 KiB | ||||
24 | Time limit exceeded | 2.063s | 3976 KiB | ||||
25 | Time limit exceeded | 2.073s | 3828 KiB | ||||
26 | Time limit exceeded | 2.059s | 4292 KiB | ||||
27 | Time limit exceeded | 2.065s | 4180 KiB | ||||
28 | Time limit exceeded | 2.065s | 3932 KiB | ||||
29 | Time limit exceeded | 2.079s | 4160 KiB | ||||
30 | Time limit exceeded | 2.065s | 4164 KiB |