Submission #587241

#TimeUsernameProblemLanguageResultExecution timeMemory
587241rainboyMed (COCI22_med)C11
50 / 50
1 ms300 KiB
#include <stdio.h> #include <string.h> #define N 500 #define L 10 #define S 500 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } char ss[N][L + 1]; int aa[N], 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 = aa[ii[j]] != aa[i_] ? aa[i_] - aa[ii[j]] : 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[N], rr[N]; int n, h, i, l, r; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", ss[i]); for (h = 0; h < 5; h++) { int a; scanf("%d", &a); aa[i] += a; } ii[i] = i; } sort(ii, 0, n); for (i = 0, l = 0, r = 0; i < n; i++) { while (aa[ii[l]] - aa[ii[i]] > S || aa[ii[l]] - aa[ii[i]] == S && strcmp(ss[ii[l]], ss[ii[i]]) < 0) l++; while (r < n && (aa[ii[i]] - aa[ii[r]] < S || aa[ii[i]] - aa[ii[r]] == S && strcmp(ss[ii[i]], ss[ii[r]]) > 0)) r++; ll[ii[i]] = l + 1, rr[ii[i]] = r; } for (i = 0; i < n; i++) printf("%d %d\n", ll[i], rr[i]); return 0; }

Compilation message (stderr)

Main.c: In function 'main':
Main.c:55:66: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   55 |   while (aa[ii[l]] - aa[ii[i]] > S || aa[ii[l]] - aa[ii[i]] == S && strcmp(ss[ii[l]], ss[ii[i]]) < 0)
      |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:57:76: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   57 |   while (r < n && (aa[ii[i]] - aa[ii[r]] < S || aa[ii[i]] - aa[ii[r]] == S && strcmp(ss[ii[i]], ss[ii[r]]) > 0))
      |                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%s", ss[i]);
      |   ^~~~~~~~~~~~~~~~~~
Main.c:48:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |    scanf("%d", &a);
      |    ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...