# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
617621 | drdilyor | Diversity (CEOI21_diversity) | C++17 | 63 ms | 12476 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef ONPC
#define cerr cout
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define sz(a) ((int)(a).size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll INFL = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
const int N = 3e5, LOGN = 17, MOD = 1e9+7;
ll brute(vector<int> arr) {
int n = sz(arr);
ll res = INFL;
do {
ll cur = 0;
for (int i = 0; i < n; i++) {
set<int> values;
for (int j = i; j < n; j++) {
values.insert(arr[j]);
cur += sz(values);
}
}
if (cur < res) {
res = cur;
debug(cur, arr);
}
} while (next_permutation(arr.begin(), arr.end()));
return res;
}
int solve() {
int n, q;
if (!(cin >> n >> q)) {
return 1;
}
vector<int> arr(n);
for (auto& i : arr) {cin >> i;}
vector<int> count(N+1);
for (int i : arr) count[i]++;
vector<pair<int,int>> bycount;
for (int i = 0; i <= N; i++) {
if (count[i]) bycount.emplace_back(count[i], i);
}
sort(bycount.begin(), bycount.end());
vector<int> brr;
for (int i = 0; i < sz(bycount); i += 2) {
brr.push_back(bycount[i].first);
}
for (int i = sz(bycount) - 1 - sz(bycount)%2; i >= 0; i-= 2){
brr.push_back(bycount[i].first);
}
debug(brr);
n = sz(brr);
ll res = 0;
vector<ll> sum(n+1);
for (int i = n-1; i >= 1; i--) {
sum[i-1] = sum[i] + brr[i];
}
vector<ll> multed(n);
for (int i = 0; i < n; i++) {
multed[i] = (i+1) * brr[i];
}
for (int i = n-1; i > 0; i--) {
multed[i-1] += multed[i];
}
debug(brr, sum, multed);
// 2x + 3y + 4z = x+y+z + 1x + 2y + 3z
for (int i = 0; i < n;i++) {
if (i < n-1)
res += brr[i] * (multed[i+1] - sum[i] * i);
res += (ll)brr[i] * (brr[i] + 1) / 2;
}
cout << res << '\n';
return 0;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
#ifdef ONPC
t = 10000;
#endif
while (t-- && cin) {
if (solve()) break;
#ifdef ONPC
cout << "____________________" << endl;
#endif
}
return 0;
}
/*
█████ █████ ███ ████
▒▒███ ▒▒███ ▒▒▒ ▒▒███
███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████
███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███
▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒
▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███
▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████
▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒
███ ▒███
▒▒██████
▒▒▒▒▒▒
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |