Submission #471237

# Submission time Handle Problem Language Result Execution time Memory
471237 2021-09-07T19:50:14 Z rainboy ZigZag (COCI17_zigzag) C
80 / 80
68 ms 5228 KB
#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

zigzag.c: In function 'main':
zigzag.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
zigzag.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%s", ss[i]);
      |   ^~~~~~~~~~~~~~~~~~
zigzag.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%s", s), a = s[0] - 'a';
      |   ^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 204 KB Output is correct
7 Correct 65 ms 5228 KB Output is correct
8 Correct 67 ms 5152 KB Output is correct
9 Correct 67 ms 5188 KB Output is correct
10 Correct 68 ms 5156 KB Output is correct