Submission #993698

#TimeUsernameProblemLanguageResultExecution timeMemory
993698vladiliusDiversity (CEOI21_diversity)C++17
0 / 100
7054 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second #define ins insert const ll inf = numeric_limits<ll> :: max(); const int A = 3e5; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin>>n>>q; vector<int> a(n + 1); for (int i = 1; i <= n; i++){ cin>>a[i]; } if (n > 11) return 0; ll out = inf; int num = 1; for (int i = 2; i <= n; i++) num *= i; vector<int> p; for (int i = 1; i <= n; i++) p.pb(i); vector<bool> used(A + 1); while (num--){ vector<int> b(n + 1); for (int i = 1; i <= n; i++) b[i] = a[p[i - 1]]; ll sum = 0; for (int i = 1; i <= n; i++){ int cnt = 0; for (int j = i; j <= n; j++){ if (!used[b[j]]){ used[b[j]] = 1; cnt++; } sum += cnt; } for (int j = i; j <= n; j++) used[b[j]] = 0; } out = min(out, sum); next_permutation(p.begin(), p.end()); } cout<<out<<"\n"; }
#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...