This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAX_PERS=300*1000+5,MAX_PROP=22,MAX_VAL=(1<<20);
int nbPers,nbChoix,rep,val,bascule,minPerdu;
int choix[MAX_PERS][MAX_PROP];
int somme[MAX_PROP];
int nbOccu[MAX_VAL];
int val1[MAX_VAL];
int compte1(int nb) {
int nb1=0;
while (nb>0) {
nb1+=nb%2;
nb/=2;
}
return nb1;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbPers>>nbChoix;
for (int i=0;i<nbPers;i++) {
for (int j=0;j<nbChoix;j++) {
cin>>choix[i][j];
somme[j]+=choix[i][j];
}
}
if (nbPers<=3000) {
for (int i=0;i<nbPers;i++) {
rep=0;
for (int j=0;j<nbPers;j++) {
if (i!=j) {
val=0;
for (int k=0;k<nbChoix;k++) {
if (somme[k]-choix[i][k]-choix[j][k]>=nbPers/2) {
val++;
}
}
rep=max(rep,val);
}
}
cout<<rep<<"\n";
}
}
else {
for (int i=0;i<(1<<nbChoix);i++) {
val1[i]=compte1(i);
}
for (int i=0;i<nbPers;i++) {
val=0;
for (int j=0;j<nbChoix;j++) {
val+=(1<<j)*choix[i][j];
}
nbOccu[val]++;
}
for (int i=0;i<nbPers;i++) {
rep=0;
minPerdu=nbChoix;
bascule=0;
val=0;
for (int j=0;j<nbChoix;j++) {
val+=(1<<j)*choix[i][j];
if (somme[j]-choix[i][j]>=nbPers/2) {
rep++;
if (somme[j]-choix[i][j]-1<nbPers/2) {
bascule+=(1<<j);
}
}
}
nbOccu[val]--;
for (int j=0;j<(1<<nbChoix);j++) {
if (nbOccu[j]>0) {
minPerdu=min(minPerdu,val1[j&bascule]);
}
}
nbOccu[val]++;
cout<<rep-minPerdu<<"\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |