Submission #824656

#TimeUsernameProblemLanguageResultExecution timeMemory
824656kshitij_sodaniRope (JOI17_rope)C++17
80 / 100
2548 ms81368 KiB
#include <bits/stdc++.h> #define a first #define b second #define pb push_back using namespace std; #define endl '\n' typedef long long llo; int it[1000001]; int ans[1000001]; int co[1000001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin>>n>>m; for(int i=0;i<m;i++){ ans[i]=n; } for(int i=0;i<n;i++){ cin>>it[i]; it[i]--; co[it[i]]++; ans[it[i]]--; } map<pair<pair<int,int>,int>,int> ss; for(int i=0;i<n-1;i++){ if(it[i]!=it[i+1]){ ss[{{min(it[i],it[i+1]),max(it[i],it[i+1])},i%2}]++; } } for(int i=0;i<m;i++){ for(int j=i+1;j<m;j++){ int cur=co[i]+co[j]; int mi=0; if(ss.find({{i,j},0})!=ss.end()){ mi=ss[{{i,j},0}]; if(ss.find({{i,j},1})!=ss.end()){ mi=min(mi,ss[{{i,j},1}]); } else{ mi=0; } } int co=cur-mi; ans[i]=min(ans[i],n-co); ans[j]=min(ans[j],n-co); } } for(int i=0;i<m;i++){ cout<<ans[i]<<endl; } return 0; }
#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...