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;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
pii operator+(const pii &a, const pii &b) { return {a.first + b.first, a.second + b.second}; }
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int N, M;
vvi A;
vi votes;
int vr; // votes required
vi trans, transR;
int dp[1 << 20][2];
void addRes(int i, int idx)
{
if (idx == dp[i][0] || idx == dp[i][1])
return;
for (int j = 0; j < 2 && idx != -1; ++j)
{
if (dp[i][j] == -1 || __builtin_popcount(trans[idx] & i) < __builtin_popcount(trans[dp[i][j]] & i))
swap(dp[i][j], idx);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
vr = N / 2;
A.assign(N, vi(M));
votes.assign(M, 0);
trans.assign(N, 0);
transR.assign(N, 0);
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < M; ++j)
{
cin >> A[i][j];
votes[j] += A[i][j];
trans[i] |= (A[i][j]) ? (1 << j) : 0;
}
}
for (int i = 0; i < 1 << M; ++i)
dp[i][0] = dp[i][1] = -1;
for (int i = 0; i < N; ++i)
addRes(((1 << M) - 1) & ~trans[i], i);
for (int i = (1 << M) - 1; i >= 0; --i)
{
for (int k = 0; k < M; ++k)
{
if (i & (1 << k))
for (int j = 0; j < 2; ++j)
addRes(i ^ (1 << k), dp[i][j]);
}
}
for (int i = 0; i < (1 << M); ++i)
{
for (int k = 0; k < M; ++k)
{
if (!(i & (1 << k)))
for (int j = 0; j < 2; ++j)
addRes(i ^ (1 << k), dp[i][j]);
}
}
for (int i = 0; i < N; ++i)
{
int ans = 0;
int pattern = 0;
for (int k = 0; k < M; ++k)
{
if (votes[k] - A[i][k] >= vr)
++ans;
if (votes[k] - A[i][k] == vr)
pattern |= 1 << k;
}
int j = dp[pattern][0];
if (j == i)
j = dp[pattern][1];
cout << ans - __builtin_popcount(pattern & trans[j]) << "\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... |