Submission #1180112

#TimeUsernameProblemLanguageResultExecution timeMemory
1180112Zbyszek99Rope (JOI17_rope)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ff first #define ss second #define vl vector<long long> #define vi vector<int> #define pii pair<int,int> #define pll pair<long long, long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace std; //mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll rand(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; map<pii,int> np_pairs; map<pii,int> p_pairs; int zlicz[1000'001]; int main() { // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random(); int n,m; cin >> n >> m; vi C(n); rep(i,n) cin >> C[i]; rep(i,n-1) { if(i % 2 == 0) { p_pairs[{C[i],C[i+1]}]++; } else { np_pairs[{C[i],C[i+1]}]++; } } rep(i,n) zlicz[C[i]]++; vector<pii> vsort; rep2(i,1,m) vsort.pb({zlicz[i],i}); sort(all(vsort)); reverse(all(vsort)); rep2(i,1,m) { int ans = n; //parz forall(it,vsort) { if(it.ss == i) { ans = min(ans,n-zlicz[it.ss]); continue; } int v = it.ss; if(p_pairs[{i,v}] + p_pairs[{v,i}] == 0) { ans = min(ans,n-zlicz[v]-zlicz[i] + (n%2 == 1 && C[n-1] != i && C[n-1] != v ? 1 : 0)); break; } ans = min(ans,(n - n%2-zlicz[v]-zlicz[i]) + (p_pairs[{i,v}] + p_pairs[{v,i}]) + (n%2 == 1 && C[n-1] != i && C[n-1] != v ? 1 : 0)); } //cout << ans << "\n"; //nparz forall(it,vsort) { if(it.ss == i) { ans = min(ans,n-zlicz[it.ss]); continue; } int v = it.ss; // cout << v << " v\n"; if(np_pairs[{i,v}] + np_pairs[{v,i}] == 0) { ans = min(ans,n-zlicz[v]-zlicz[i] + (n%2 == 1 && C[0] != i && C[0] != v ? 1 : 0)); break; } // cout << np_pairs[{i,v}] << " " << np_pairs[{v,i}] << " " << np_pairs[{i,i}] << " " << np_pairs[{v,v}] << " pairs\n"; ans = min(ans,(n - n%2 - zlicz[i] - zlicz[v]) + (np_pairs[{i,v}] + np_pairs[{v,i}]) + (n%2 == 1 && C[0] != i && C[0] != v ? 1 : 0)); } cout << ans << "\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...