Submission #748171

#TimeUsernameProblemLanguageResultExecution timeMemory
748171NemanjaSo2005Council (JOI23_council)C++17
0 / 100
1362 ms37924 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; int kritv,N,M,K,maks[300005],maska[300005],glasa[300005][25],ukup[25],res[300005],dist[1050005]; map<int,bool> bio; const int stepen[25]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216}; /* 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){ if(bio[x]) return; bio[x]=true; rek1(0,(stepen[M]-1)^x,0,0); return; } void rek2(int poz,int targ,int tren,int cena,int indx){ if(res[indx]<=cena) return; if(poz>=M){ res[indx]=min(res[indx],cena+dist[tren]); return; } /// Dodaje 1 rek2(poz+1,targ,tren+stepen[poz],cena,indx); /// Dodaje 0 if((targ&stepen[poz])!=0) rek2(poz+1,targ,tren,cena+1,indx); else rek2(poz+1,targ,tren,cena,indx); return; } void najblizi(int indx,int sta){ rek2(K,sta,sta&(stepen[K]-1),0,indx); return; } int main(){ srand(532); ios_base::sync_with_stdio(false); cin.tie(0); N=3e5; M=20; kritv=N/2; K=(M/2); for(int i=1;i<=N;i++){ for(int j=0;j<M;j++) /*cin>>*/ if((i<=N/2 and j<=M/2) or (i>N/2 and j>M/2)) glasa[i][j]=1; else glasa[i][j]=0; 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; bio.clear(); 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; bio.clear(); 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...