# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
123919 | 2019-07-02T09:38:08 Z | songc | 즐거운 채소 기르기 (JOI14_growing) | C++14 | 152 ms | 9316 KB |
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; int N; int A[303030], L[303030], R[303030], T[303030]; vector<int> comp; LL ans; void update(int t){ while (t<=N){ T[t]++; t += t & -t; } } int read(int t){ int ret=0; while (t){ ret += T[t]; t -= t & -t; } return ret; } int main(){ scanf("%d", &N); for (int i=1; i<=N; i++) { scanf("%d", &A[i]); comp.push_back(A[i]); } sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); for (int i=1; i<=N; i++) A[i] = lower_bound(comp.begin(), comp.end(), A[i]) - comp.begin() + 1; for (int i=1; i<=N; i++){ L[i] = read(N)-read(A[i]); update(A[i]); } memset(T, 0, sizeof T); for (int i=N; i>=1; i--){ R[i] = read(N)-read(A[i]); update(A[i]); } for (int i=1; i<=N; i++) ans += min(L[i], R[i]); printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1528 KB | Output is correct |
2 | Correct | 4 ms | 1528 KB | Output is correct |
3 | Correct | 3 ms | 1552 KB | Output is correct |
4 | Correct | 3 ms | 1528 KB | Output is correct |
5 | Correct | 3 ms | 1528 KB | Output is correct |
6 | Correct | 3 ms | 1528 KB | Output is correct |
7 | Correct | 3 ms | 1528 KB | Output is correct |
8 | Correct | 3 ms | 1528 KB | Output is correct |
9 | Correct | 3 ms | 1528 KB | Output is correct |
10 | Correct | 3 ms | 1528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1656 KB | Output is correct |
2 | Correct | 3 ms | 1528 KB | Output is correct |
3 | Correct | 3 ms | 1528 KB | Output is correct |
4 | Correct | 3 ms | 1528 KB | Output is correct |
5 | Correct | 3 ms | 1528 KB | Output is correct |
6 | Correct | 3 ms | 1528 KB | Output is correct |
7 | Correct | 3 ms | 1528 KB | Output is correct |
8 | Correct | 3 ms | 1528 KB | Output is correct |
9 | Correct | 3 ms | 1528 KB | Output is correct |
10 | Correct | 3 ms | 1528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1528 KB | Output is correct |
2 | Correct | 3 ms | 1528 KB | Output is correct |
3 | Correct | 4 ms | 1528 KB | Output is correct |
4 | Correct | 4 ms | 1656 KB | Output is correct |
5 | Correct | 5 ms | 1656 KB | Output is correct |
6 | Correct | 4 ms | 1656 KB | Output is correct |
7 | Correct | 4 ms | 1656 KB | Output is correct |
8 | Correct | 5 ms | 1656 KB | Output is correct |
9 | Correct | 6 ms | 1656 KB | Output is correct |
10 | Correct | 5 ms | 1656 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 2804 KB | Output is correct |
2 | Correct | 55 ms | 4212 KB | Output is correct |
3 | Correct | 83 ms | 5224 KB | Output is correct |
4 | Correct | 119 ms | 6764 KB | Output is correct |
5 | Correct | 68 ms | 6760 KB | Output is correct |
6 | Correct | 41 ms | 4208 KB | Output is correct |
7 | Correct | 92 ms | 6916 KB | Output is correct |
8 | Correct | 135 ms | 9188 KB | Output is correct |
9 | Correct | 141 ms | 9316 KB | Output is correct |
10 | Correct | 152 ms | 9316 KB | Output is correct |