Submission #26007

# Submission time Handle Problem Language Result Execution time Memory
26007 2017-06-26T06:07:05 Z kajebiii 컬러볼 (KOI15_ball) C++14
25 / 25
139 ms 5928 KB
// =====================================================================================
//
//       Filename:  10800.cpp
//
//    Description:  BOJ
//
//        Version:  1.0
//        Created:  09/23/2016 13:21:20
//       Revision:  none
//       Compiler:  g++
//
//         Author:  JongBeom Kim (KJBS2), [email protected]
//   Organization:  KJBS2
//
// =====================================================================================

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <math.h>
#include <assert.h>

using namespace std;

typedef pair<int, int> pi;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#ifndef ONLINE_JUDGE
const bool debug = true;
#else
const bool debug = false;
#endif
pi operator +(const pi &x, const pi &y) {return mp(x.fi+y.fi, x.se+y.se);}

const int INF = 0x7fffffff;
const pi Ch[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};
const int MAX_N = 2e5 + 200, MAX_S = 2e3 + 100;

struct NODE
{
	int c, s, ix;
	NODE() {c = s = ix = -1;}
	NODE(int _c, int _s, int _ix) {c = _c, s = _s, ix = _ix;}
	const bool operator<(const NODE &o) const{return s < o.s;}
}Ball[MAX_N];
int Ans[MAX_N], Sum[MAX_N], SumV, N;
int main() {
	cin >> N;
	for(int i=0; i<N; i++)
	{
		scanf("%d%d", &Ball[i].c, &Ball[i].s);
		Ball[i].ix = i;
	}
	sort(Ball, Ball + N);
	for(int l=0; l<N; )
	{
		int r = l;
		while(r < N && Ball[r].s == Ball[l].s) r++;
		for(int i=l; i<r; i++)
			Ans[Ball[i].ix] = SumV - Sum[Ball[i].c];
		for(int i=l; i<r; i++)
		{
			Sum[Ball[i].c] += Ball[i].s;
			SumV += Ball[i].s;
		}
		l = r;
	}
	for(int i=0; i<N; i++) printf("%d\n", Ans[i]);
	return 0;
}










Compilation message

ball.cpp: In function 'int main()':
ball.cpp:62:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &Ball[i].c, &Ball[i].s);
                                        ^
# Verdict Execution time Memory Grader output
1 Correct 86 ms 5928 KB Output is correct
2 Correct 109 ms 5928 KB Output is correct
3 Correct 103 ms 5928 KB Output is correct
4 Correct 133 ms 5928 KB Output is correct
5 Correct 109 ms 5928 KB Output is correct
6 Correct 3 ms 5928 KB Output is correct
7 Correct 3 ms 5928 KB Output is correct
8 Correct 3 ms 5928 KB Output is correct
9 Correct 0 ms 5928 KB Output is correct
10 Correct 0 ms 5928 KB Output is correct
11 Correct 86 ms 5928 KB Output is correct
12 Correct 89 ms 5928 KB Output is correct
13 Correct 93 ms 5928 KB Output is correct
14 Correct 73 ms 5928 KB Output is correct
15 Correct 89 ms 5928 KB Output is correct
16 Correct 89 ms 5928 KB Output is correct
17 Correct 73 ms 5928 KB Output is correct
18 Correct 109 ms 5928 KB Output is correct
19 Correct 99 ms 5928 KB Output is correct
20 Correct 139 ms 5928 KB Output is correct