Submission #471237

#TimeUsernameProblemLanguageResultExecution timeMemory
471237rainboyZigZag (COCI17_zigzag)C11
80 / 80
68 ms5228 KiB
#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)

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 timeMemoryGrader output
Fetching results...