Submission #930927

#TimeUsernameProblemLanguageResultExecution timeMemory
930927rainboy컬러볼 (KOI15_ball)C11
25 / 25
74 ms8232 KiB
#include <stdio.h> #define N 200000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int cc[N], ww[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) if (ww[ii[j]] == ww[i_]) j++; else if (ww[ii[j]] < ww[i_]) { 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 ii[N], ss[N], ans[N]; int n, h, i, i_, j, sum; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d%d", &cc[i], &ww[i]), cc[i]--; for (i = 0; i < n; i++) ii[i] = i; sort(ii, 0, n); sum = 0; for (i = 0; i < n; i = j) { j = i + 1; while (j < n && ww[ii[j]] == ww[ii[i]]) j++; for (h = i; h < j; h++) { i_ = ii[h]; ans[i_] = sum - ss[cc[i_]]; } for (h = i; h < j; h++) { i_ = ii[h]; sum += ww[i_], ss[cc[i_]] += ww[i_]; } } for (i = 0; i < n; i++) printf("%d\n", ans[i]); return 0; }

Compilation message (stderr)

ball.c: In function 'main':
ball.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
ball.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d", &cc[i], &ww[i]), cc[i]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...