Submission #940835

#TimeUsernameProblemLanguageResultExecution timeMemory
940835velislavgarkovCouncil (JOI23_council)C++14
16 / 100
4075 ms4660 KiB
#include <iostream> using namespace std; const int MAXN=3e5+10; const int MAXM=(1<<20); struct Answer { int ans1, ind1; int ans2, ind2; }; int n, m; int a[MAXN], cnt[32]; Answer dp[MAXM][25]; bool fbit(int x, int bit) { return (x & (1<<bit)); } Answer find_dp(int mask, int m) { Answer res={0,0,0,0}; for (int i=1;i<=n;i++) { int s=__builtin_popcount((~a[i])&mask); if (s>res.ans1) { res.ans2=res.ans1; res.ind2=res.ind2; res.ans1=s; res.ind1=i; } else if (s>res.ans2) { res.ans2=s; res.ind2=i; } } return res; } int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; int bit; for (int i=1;i<=n;i++) { for (int j=0;j<m;j++) { cin >> bit; a[i]+=(bit<<j); cnt[j]+=bit; } } for (int i=1;i<=n;i++) { int ans=0, mask=0; for (int j=0;j<m;j++) { if (cnt[j]>=n/2+2) ans++; else if (cnt[j]==n/2+1) { if (!fbit(a[i],j)) ans++; else mask+=(1<<j); } else if (cnt[j]==n/2 && !fbit(a[i],j)) mask+=(1<<j); } Answer res=find_dp(mask,m-1); if (res.ind1!=i) ans+=res.ans1; else ans+=res.ans2; cout << ans << endl; } 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...