# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
471171 |
2021-09-07T15:30:18 Z |
rainboy |
ZigZag (COCI17_zigzag) |
C |
|
72 ms |
5852 KB |
#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
zigzag.c: In function 'srand_':
zigzag.c:15:16: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
15 | X = tv.tv_sec ^ tv.tv_usec | 1;
| ~~~~~~~~~~^~~~~~~~~~~~
zigzag.c: In function 'main':
zigzag.c:51:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
zigzag.c:53:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%s", ss[i]);
| ^~~~~~~~~~~~~~~~~~
zigzag.c:66:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%s", s), a = s[0] - 'a';
| ^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
67 ms |
5812 KB |
Output is correct |
8 |
Correct |
72 ms |
5756 KB |
Output is correct |
9 |
Correct |
68 ms |
5824 KB |
Output is correct |
10 |
Correct |
67 ms |
5852 KB |
Output is correct |