Submission #159850

#TimeUsernameProblemLanguageResultExecution timeMemory
159850geon040702컬러볼 (KOI15_ball)C++14
25 / 25
130 ms8440 KiB
#include <stdio.h> #include <stdlib.h> #include <algorithm> using namespace std; #define N 200010 int n, s[N], total; int size[N], color[N], cnt; struct A { int size, color, index; int sum; } ; A a[N]; bool comp(A x, A y) { return x.size < y.size; } bool comp2(A x, A y) { return x.index < y.index; } int main() { int i, j; scanf("%d", &n); for(i=1;i<=n;i++) { scanf("%d %d", &a[i].color, &a[i].size); a[i].index = i; } sort(a+1, a+n+1, comp); for(i=1;i<=n;i++) { if(a[i].size != a[i-1].size) { for(j=1;j<=cnt;j++) { s[color[j]] += size[j]; total += size[j]; } cnt = 0; } cnt++; size[cnt] = a[i].size; color[cnt] = a[i].color; a[i].sum = total - s[a[i].color]; } sort(a + 1, a + n + 1, comp2); for(i=1;i<=n;i++) { printf("%d\n", a[i].sum); } return 0; }

Compilation message (stderr)

ball.cpp: In function 'int main()':
ball.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
ball.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a[i].color, &a[i].size);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...