답안 #18545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
18545 2016-02-08T14:35:25 Z choyi0521 즐거운 채소 기르기 (JOI14_growing) C++14
0 / 100
17 ms 4600 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
const int MAX_N = 300000;
int n, bit[MAX_N + 1];
pair<int,int> p[MAX_N];
void update(int h) {
	for (; h <= n; h += h&-h) bit[h]++;
}
int query(int h) {
	int s = 0;
	for (; h; h -= h&-h) s += bit[h];
	return s;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i <n; i++) {
		scanf("%d", &p[i].first);
		p[i].second = i+1;
	}
	sort(p, p +n);
	int res = 0;
	for (int i = n-1,j=n-1; i >= 0; i--) {
		res += min(query(p[i].second - 1), query(n) - query(p[i].second));
		if (!i || p[i].second == p[i - 1].second) continue;
		for (; j >= i; j--) update(p[j].second);
	}
	printf("%d", res);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4600 KB Output is correct
2 Correct 0 ms 4600 KB Output is correct
3 Correct 0 ms 4600 KB Output is correct
4 Correct 1 ms 4600 KB Output is correct
5 Correct 0 ms 4600 KB Output is correct
6 Correct 1 ms 4600 KB Output is correct
7 Correct 0 ms 4600 KB Output is correct
8 Correct 0 ms 4600 KB Output is correct
9 Correct 0 ms 4600 KB Output is correct
10 Incorrect 1 ms 4600 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4600 KB Output is correct
2 Incorrect 0 ms 4600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4600 KB Output is correct
2 Incorrect 2 ms 4600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -