답안 #6113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
6113 2014-06-19T20:56:54 Z kriii 즐거운 채소 기르기 (JOI14_growing) C++
100 / 100
316 ms 19888 KB
#include <stdio.h>
#include <map>
using namespace std;

int N,D[300030],L[300030],R[300030],B[300030],C;
map<int, int> chk;

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<N;i++) scanf ("%d",&D[i]), chk[D[i]] = 0;
	for (map<int,int>::iterator I = chk.begin(); I != chk.end(); I++) I->second = ++C;
	for (int i=0;i<N;i++) D[i] = chk[D[i]];

	for (int i=0;i<N;i++){
		L[i] = i;
		for (int x=D[i];x;x-=x&(-x)) L[i] -= B[x];
		for (int x=D[i];x<=C;x+=x&(-x)) B[x]++;
	}

	for (int i=1;i<=C;i++) B[i] = 0;
	for (int i=N-1;i>=0;i--){
		R[i] = N-1-i;
		for (int x=D[i];x;x-=x&(-x)) R[i] -= B[x];
		for (int x=D[i];x<=C;x+=x&(-x)) B[x]++;
	}

	long long ans = 0;
	for (int i=0;i<N;i++) ans += L[i] < R[i] ? L[i] : R[i];

	printf ("%lld\n",ans);

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5896 KB Output is correct
2 Correct 0 ms 5896 KB Output is correct
3 Correct 0 ms 5896 KB Output is correct
4 Correct 0 ms 5896 KB Output is correct
5 Correct 0 ms 5896 KB Output is correct
6 Correct 0 ms 5896 KB Output is correct
7 Correct 0 ms 5896 KB Output is correct
8 Correct 0 ms 5896 KB Output is correct
9 Correct 0 ms 5896 KB Output is correct
10 Correct 0 ms 5896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5896 KB Output is correct
2 Correct 0 ms 5896 KB Output is correct
3 Correct 0 ms 5896 KB Output is correct
4 Correct 0 ms 5896 KB Output is correct
5 Correct 0 ms 5896 KB Output is correct
6 Correct 0 ms 5896 KB Output is correct
7 Correct 0 ms 5896 KB Output is correct
8 Correct 0 ms 5896 KB Output is correct
9 Correct 0 ms 5896 KB Output is correct
10 Correct 0 ms 5896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5896 KB Output is correct
2 Correct 0 ms 5896 KB Output is correct
3 Correct 0 ms 5896 KB Output is correct
4 Correct 0 ms 6028 KB Output is correct
5 Correct 0 ms 6028 KB Output is correct
6 Correct 0 ms 5896 KB Output is correct
7 Correct 0 ms 5896 KB Output is correct
8 Correct 0 ms 6028 KB Output is correct
9 Correct 0 ms 6028 KB Output is correct
10 Correct 0 ms 6028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5896 KB Output is correct
2 Correct 116 ms 10516 KB Output is correct
3 Correct 160 ms 11836 KB Output is correct
4 Correct 240 ms 13948 KB Output is correct
5 Correct 148 ms 15136 KB Output is correct
6 Correct 52 ms 10516 KB Output is correct
7 Correct 48 ms 5896 KB Output is correct
8 Correct 216 ms 19888 KB Output is correct
9 Correct 224 ms 12892 KB Output is correct
10 Correct 316 ms 19888 KB Output is correct