Submission #65404026
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>#include <inttypes.h>struct yagi_s {int64_t pos;int id;};int cmp(const void* x, const void* y) {struct yagi_s a = *(const struct yagi_s*)x, b = *(const struct yagi_s*)y;return a.pos < b.pos ? -1 : a.pos > b.pos;}int N;int64_t A[212345];int Q;int64_t B[212345];struct yagi_s y[212345];
#include <stdio.h> #include <stdlib.h> #include <inttypes.h> struct yagi_s { int64_t pos; int id; }; int cmp(const void* x, const void* y) { struct yagi_s a = *(const struct yagi_s*)x, b = *(const struct yagi_s*)y; return a.pos < b.pos ? -1 : a.pos > b.pos; } int N; int64_t A[212345]; int Q; int64_t B[212345]; struct yagi_s y[212345]; int main(void) { int i; if (scanf("%d", &N) != 1) return 1; for (i = 0; i < N; i++) { if (scanf("%" SCNd64, &A[i]) != 1) return 1; y[i + 1].pos = A[i]; y[i + 1].id = i + 1; } if (scanf("%d", &Q) != 1) return 1; for (i = 0; i < Q; i++) { if (scanf("%" SCNd64, &B[i]) != 1) return 1; } qsort(y + 1, N, sizeof(*y), cmp); y[0].pos = -INT64_C(3123456789012345678); y[N + 1].pos = INT64_C(3123456789012345678); for (i = 0; i < Q; i++) { int le = 0, g = N + 1; while (le + 1 < g) { int m = le + (g - le) / 2; if (y[m].pos <= B[i]) le = m; else g = m; } if ( B[i] - y[le].pos < y[g].pos - B[i] || ( B[i] - y[le].pos == y[g].pos - B[i] && y[le].id < y[g].id ) ) { printf("%d\n", y[le].id); y[le].pos = B[i]; } else { printf("%d\n", y[g].id); y[g].pos = B[i]; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Goats |
User | mikecat |
Language | C (gcc 12.2.0) |
Score | 200 |
Code Size | 1246 Byte |
Status | AC |
Exec Time | 141 ms |
Memory | 10748 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt |
All | 00_sample_00.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 03_max_00.txt, 03_max_01.txt, 03_max_02.txt, 03_max_03.txt, 04_min_00.txt, 04_min_01.txt, 04_min_02.txt, 04_min_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 0 ms | 1748 KB |
01_random_00.txt | AC | 48 ms | 4912 KB |
01_random_01.txt | AC | 87 ms | 9144 KB |
01_random_02.txt | AC | 99 ms | 9160 KB |
01_random_03.txt | AC | 43 ms | 5172 KB |
01_random_04.txt | AC | 86 ms | 8704 KB |
01_random_05.txt | AC | 59 ms | 6224 KB |
01_random_06.txt | AC | 122 ms | 10532 KB |
01_random_07.txt | AC | 59 ms | 4868 KB |
02_handmade_00.txt | AC | 58 ms | 5128 KB |
02_handmade_01.txt | AC | 45 ms | 3152 KB |
02_handmade_02.txt | AC | 77 ms | 8348 KB |
02_handmade_03.txt | AC | 59 ms | 6568 KB |
02_handmade_04.txt | AC | 104 ms | 7772 KB |
02_handmade_05.txt | AC | 107 ms | 8116 KB |
02_handmade_06.txt | AC | 62 ms | 4200 KB |
02_handmade_07.txt | AC | 85 ms | 8436 KB |
03_max_00.txt | AC | 71 ms | 9460 KB |
03_max_01.txt | AC | 116 ms | 10092 KB |
03_max_02.txt | AC | 141 ms | 10748 KB |
03_max_03.txt | AC | 90 ms | 9716 KB |
04_min_00.txt | AC | 44 ms | 3064 KB |
04_min_01.txt | AC | 19 ms | 2204 KB |
04_min_02.txt | AC | 34 ms | 2896 KB |
04_min_03.txt | AC | 34 ms | 2912 KB |