# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471171 | rainboy | ZigZag (COCI17_zigzag) | C11 | 72 ms | 5852 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>
#include <sys/time.h>
#define N 100000
#define L 21
#define A 26
unsigned int X;
void srand_() {
struct timeval tv;
gettimeofday(&tv, NULL);
X = tv.tv_sec ^ tv.tv_usec | 1;
}
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;
srand_();
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... |