Submission #857987

#TimeUsernameProblemLanguageResultExecution timeMemory
857987danikoynovDiversity (CEOI21_diversity)C++14
14 / 100
7069 ms5788 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); } const int maxn = 3e5 + 10; int n, q, a[maxn], cnt[maxn], m, val[maxn], used[maxn]; vector < ll > groups; ll ans; void check() { ll tot = 0; /**for (int i = 0; i < m; i ++) cout << val[i] << " "; cout << endl;*/ for (ll i = 0; i < m; i ++) for (ll j = i + 1; j < m; j ++) { tot = tot + groups[val[i]] * groups[val[j]] * (j - i + 1); } for (int i = 0; i < m; i ++) { ll cur = groups[i]; tot = tot + cur * (cur + 1) / 2; } ans = min(ans, tot); } void perm(int pos) { if (pos == m) check(); else { for (int i = 0; i < m; i ++) { if (!used[i]) { val[pos] = i; used[i] = 1; perm(pos + 1); used[i] = 0; val[pos] = 0; } } } } void solve() { cin >> n >> q; for (int i = 1; i <= n; i ++) cin >> a[i]; int l, r; cin >> l >> r; for (int i = 1; i <= n; i ++) cnt[a[i]] ++; for (int i = 1; i <= n; i ++) if (cnt[i] > 0) groups.push_back((ll)(cnt[i])); ans = 1e18; m = groups.size(); perm(0); cout << ans << endl; } int main() { solve(); return 0; } /** 4 1 1 1 1 1 1 2 2 4 4 1 2 1 3 2 1 4 */

Compilation message (stderr)

diversity.cpp: In function 'void solve()':
diversity.cpp:73:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   73 |     for (int i = 1; i <= n; i ++)
      |     ^~~
diversity.cpp:77:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   77 |         ans = 1e18;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...