# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471237 | rainboy | ZigZag (COCI17_zigzag) | C11 | 68 ms | 5228 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 100000
#define L 21
#define A 26
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
char ss[N][L + 1]; int ii[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = strcmp(ss[ii[j]], ss[i_]);
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int ll[A], rr[A], kk[A];
int n, m, i, a;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%s", ss[i]);
for (i = 0; i < n; i++)
ii[i] = i;
sort(ii, 0, n);
for (a = 0, i = 0; a < A; a++) {
ll[a] = i;
while (i < n && ss[ii[i]][0] == a + 'a')
i++;
rr[a] = i;
}
while (m--) {
static char s[2];
scanf("%s", s), a = s[0] - 'a';
printf("%s\n", ss[ii[ll[a] + kk[a]++ % (rr[a] - ll[a])]]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |