제출 #748184

#제출 시각아이디문제언어결과실행 시간메모리
748184NemanjaSo2005Council (JOI23_council)C++17
100 / 100
2385 ms335156 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]; 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}; int dist[1050005][2]; int koji[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 */ queue<pair<int,int> > Q[25]; pair<int,int> pp; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin>>N>>M; kritv=N/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][0]=dist[i][1]=M+1; ///BFS for(int i=1;i<=N;i++) Q[0].push({maska[i]^(stepen[M]-1),i}); for(int q=0;q<=M;q++){ while(Q[q].size()){ pp=Q[q].front(); Q[q].pop(); if(koji[pp.first]==pp.second) continue; if(dist[pp.first][0]!=M+1 and dist[pp.first][1]!=M+1) continue; if(dist[pp.first][0]==M+1){ dist[pp.first][0]=q; koji[pp.first]=pp.second; } else dist[pp.first][1]=q; for(int j=0;j<M;j++){ if((stepen[j]&pp.first)==0) Q[q+1].push({pp.first^stepen[j],pp.second}); else Q[q].push({pp.first^stepen[j],pp.second}); } } } for(int i=1;i<=N;i++){ int x=0; for(int j=0;j<M;j++){ int kol=ukup[j]-glasa[i][j]; if(kol==kritv) x+=stepen[j]; } if(koji[x]==i) res[i]=dist[x][1]; else res[i]=dist[x][0]; } for(int i=1;i<=N;i++) cout<<maks[i]-res[i]<<"\n"; 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...