Submission #747998

#TimeUsernameProblemLanguageResultExecution timeMemory
747998NemanjaSo2005Council (JOI23_council)C++14
0 / 100
68 ms62276 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; int kritv,N,M,K,maks[25],maska[300005],glasa[300005][25],stepen[25],ukup[25],res[300005],dist[1050005]; /* 0 - Moze a ne mora za to da ne glasa 1 - Mora da to da ne glasa Dodavanje - 0 u 1 dodaje 1 cene Ispitivanje - 1 u 0 dodaje 1 cene */ void rek1(int poz,int targ,int tren,int cena){ if(poz>=K){ tren+=(targ&(stepen[M]-stepen[K])); dist[tren]=min(dist[tren],cena); return; } ///Dodaje 0 rek1(poz+1,targ,tren,cena); ///Dodaje 1 if((targ&stepen[poz])==0) rek1(poz+1,targ,tren+stepen[poz],cena+1); else rek1(poz+1,targ,tren+stepen[poz],cena); return; } void dodaj(int x){ rek1(0,(stepen[M]-1)^x,0,0); return; } void rek2(int poz,int targ,int tren,int cena,int indx){ if(poz>=M){ res[indx]=min(res[indx],cena+dist[tren]); return; } /// Dodaje 0 if((targ&stepen[poz])!=0) rek2(poz+1,targ,tren,cena+1,indx); else rek2(poz+1,targ,tren,cena,indx); /// Dodaje 1 rek2(poz+1,targ,tren+stepen[poz],cena,indx); return; } void najblizi(int indx,int sta){ rek2(K,sta,sta&(stepen[K]-1),0,indx); return; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin>>N>>M; kritv=N/2; stepen[0]=1; for(int i=1;i<=24;i++) stepen[i]=stepen[i-1]*2; K=(M/2); for(int i=1;i<=N;i++){ for(int j=0;j<M;j++) cin>>glasa[i][j]; for(int j=0;j+j<M;j++) swap(glasa[i][j],glasa[i][M-1-j]); for(int j=0;j<M;j++){ ukup[j]+=glasa[i][j]; maska[i]+=stepen[j]*glasa[i][j]; } } for(int i=1;i<=N;i++) for(int j=0;j<M;j++) if(ukup[j]-glasa[i][j]>=kritv) maks[i]++; for(int i=1;i<=N;i++) res[i]=M+1; for(int i=0;i<=1050000;i++) dist[i]=M+1; for(int i=2;i<=N;i++){ dodaj(maska[i-1]); int x=0; for(int j=0;j<M;j++){ int kol=ukup[j]-glasa[i][j]; if(kol==kritv) x+=stepen[j]; } najblizi(i,x); } for(int i=0;i<=1050000;i++) dist[i]=M+1; for(int i=N-1;i>=1;i--){ dodaj(maska[i+1]); int x=0; for(int j=0;j<M;j++){ int kol=ukup[j]-glasa[i][j]; if(kol==kritv) x+=stepen[j]; } najblizi(i,x); } for(int i=1;i<=N;i++) cout<<maks[i]-res[i]<<"\n"; cout<<"\n"; /* for(int i=1;i<=N;i++) cout<<maks[i]<<" "; cout<<"\n"; for(int i=1;i<=N;i++) cout<<res[i]<<" "; cout<<"\n";*/ 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...