1920 | 2022-12-10 17:29:45 | KovácsHunor | Forma-1 | cpp11 | Runtime error 0/100 | 2.086s | 5716 KiB |
#include "stdio.h"
#include "stdlib.h"
long long compare(const void* a, const void* b){
return *(long long*)a-*(long long*)b;
}
void QuickSort(long long* arr, long long* index, long long size){
long long pivot = 0;
for (long long 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()
{
long long n, q;
scanf("%lld", &n);
long long* arr = (long long*)malloc(sizeof(long long)*n*3);
for (long long i = 0; i < n; i++)
{
scanf("%lld%lld%lld", arr + i, arr + i + n, arr + i + 2*n);
}
scanf("%lld", &q);
long long* sol = (long long*)malloc(sizeof(long long)*q);
long long* dis = (long long*)malloc(sizeof(long long)*n);
long long* index = (long long*)malloc(sizeof(long long)*n);
for (long long i = 0; i < q; i++)
{
long long p, t;
scanf("%lld%lld", &p, &t);
for (long long j = 0; j < n; j++)
{
index[j] = j+1;
}
for (long long 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 (long long i = 0; i < q; i++)
{
printf("%lld\n", sol[i]);
}
free(arr);
free(sol);
free(dis);
return 1;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 3ms | 1364 KiB | ||||
subtask2 | 0/20 | ||||||
2 | Runtime error | 83ms | 4468 KiB | ||||
3 | Runtime error | 87ms | 4616 KiB | ||||
4 | Runtime error | 83ms | 4836 KiB | ||||
5 | Runtime error | 81ms | 5052 KiB | ||||
6 | Runtime error | 86ms | 5240 KiB | ||||
7 | Runtime error | 82ms | 5444 KiB | ||||
8 | Runtime error | 82ms | 5640 KiB | ||||
9 | Runtime error | 81ms | 5716 KiB | ||||
subtask3 | 0/30 | ||||||
10 | Time limit exceeded | 2.068s | 2856 KiB | ||||
11 | Time limit exceeded | 2.015s | 3028 KiB | ||||
12 | Time limit exceeded | 2.062s | 3124 KiB | ||||
13 | Time limit exceeded | 2.052s | 3064 KiB | ||||
14 | Time limit exceeded | 2.061s | 3056 KiB | ||||
15 | Time limit exceeded | 2.065s | 3404 KiB | ||||
16 | Time limit exceeded | 2.055s | 3148 KiB | ||||
17 | Time limit exceeded | 2.056s | 3444 KiB | ||||
18 | Time limit exceeded | 2.049s | 3196 KiB | ||||
subtask4 | 0/50 | ||||||
19 | Time limit exceeded | 2.052s | 3668 KiB | ||||
20 | Time limit exceeded | 2.052s | 3548 KiB | ||||
21 | Time limit exceeded | 2.052s | 3812 KiB | ||||
22 | Time limit exceeded | 2.056s | 3432 KiB | ||||
23 | Time limit exceeded | 2.025s | 3448 KiB | ||||
24 | Time limit exceeded | 2.046s | 3428 KiB | ||||
25 | Time limit exceeded | 2.052s | 3816 KiB | ||||
26 | Time limit exceeded | 2.046s | 3996 KiB | ||||
27 | Time limit exceeded | 2.058s | 3976 KiB | ||||
28 | Time limit exceeded | 2.086s | 3936 KiB | ||||
29 | Time limit exceeded | 2.016s | 3836 KiB | ||||
30 | Time limit exceeded | 2.013s | 4436 KiB |