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;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m; cin>>n>>m;
vector<vector<bool>> a(n + 1, vector<bool>(m + 1));
vector<int> A[m + 1], B[n + 1];
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
bool b; cin>>b;
if (b){
A[j].pb(i);
B[i].pb(j);
}
a[i][j] = b;
}
}
vector<int> x(m + 1);
for (int i = 1; i <= m; i++) x[i] = (int) A[i].size();
vector<int> tw(m + 1); tw[0] = 1;
for (int i = 1; i <= m; i++){
tw[i] = tw[i - 1] * 2;
}
vector<int> F[tw[m]];
vector<int> y(n + 1);
function<void(int, int)> rec = [&](int i, int v){
if (i == m + 1){
F[v] = y;
return;
}
rec(i + 1, v);
for (int j: A[i]){
y[j]++;
}
rec(i + 1, v + tw[i - 1]);
for (int j: A[i]){
y[j]--;
}
};
rec(1, 0);
vector<vector<int>> p1(tw[m], vector<int>(n + 1)), p2(tw[m], vector<int>(n + 2));
for (int i = 0; i < tw[m]; i++){
p1[i][0] = 1e9;
for (int j = 1; j <= n; j++){
p1[i][j] = min(p1[i][j - 1], F[i][j]);
}
p2[i][n + 1] = 1e9;
for (int j = n; j > 0; j--){
p2[i][j] = min(p2[i][j + 1], F[i][j]);
}
}
const int M = n / 2;
vector<int> all;
for (int i = 1; i <= n; i++){
for (int j: B[i]) x[j]--;
all.clear();
int f = m;
for (int j = 1; j <= m; j++){
if (x[j] != M){
f -= (x[j] < M);
continue;
}
all.pb(j);
}
int v = 0;
for (int j: all){
v += tw[j - 1];
}
cout<<f - min(p1[v][i - 1], p2[v][i + 1])<<"\n";
for (int j: B[i]) x[j]++;
}
}
# | 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... |