Submission #83439

#TimeUsernameProblemLanguageResultExecution timeMemory
83439Bodo171Rope (JOI17_rope)C++14
100 / 100
1545 ms121688 KiB
#include <iostream> #include <fstream> #include <vector> using namespace std; const int nmax=1000*1000+5; vector<int> l[nmax],v[nmax]; int pr[nmax]; int comb[nmax]; int a[nmax],ap[nmax],ans[nmax]; int n,m,i,j,nr,pnt; int check(int a,int b) { return n-(ap[a]+ap[b]-comb[b]); } void solve(int st,int dr) { for(i=1;i<=m;i++) v[i].clear(); for(i=st;i<dr;i+=2) if(a[i]!=a[i+1]) { v[a[i]].push_back(a[i+1]); v[a[i+1]].push_back(a[i]); } for(i=1;i<=m;i++) { for(j=0;j<v[i].size();j++) comb[v[i][j]]++; for(j=0;j<v[i].size();j++) ans[i]=min(check(i,v[i][j]),ans[i]); pnt=m; while(pnt>0&&(comb[pr[pnt]]||pr[pnt]==i)) pnt--; if(pnt) ans[i]=min(check(i,pr[pnt]),ans[i]); for(j=0;j<v[i].size();j++) comb[v[i][j]]--; } } int main() { //freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n>>m; for(i=1;i<=m;i++) ans[i]=n; for(i=1;i<=n;i++) { cin>>a[i]; ap[a[i]]++; ans[a[i]]--; } nr=0; for(i=1;i<=m;i++) l[ap[i]].push_back(i); for(i=1;i<=n;i++) for(j=0;j<l[i].size();j++) pr[++nr]=l[i][j]; solve(1,n-n%2); solve(2,n-1+n%2); for(i=1;i<=m;i++) cout<<ans[i]<<'\n'; return 0; }

Compilation message (stderr)

rope.cpp: In function 'void solve(int, int)':
rope.cpp:27:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<v[i].size();j++)
                 ~^~~~~~~~~~~~
rope.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<v[i].size();j++)
                 ~^~~~~~~~~~~~
rope.cpp:36:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<v[i].size();j++)
                 ~^~~~~~~~~~~~
rope.cpp: In function 'int main()':
rope.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<l[i].size();j++)
                 ~^~~~~~~~~~~~
#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...