이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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> y(n + 1), out(n + 1), p1(n + 1), p2(n + 2), d[tw[m]];
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];
}
d[v].pb(i);
out[i] = f;
for (int j: B[i]) x[j]++;
}
function<void(int, int)> rec = [&](int i, int v){
if (i == m + 1){
p1[0] = 1e9;
for (int j = 1; j <= n; j++){
p1[j] = min(p1[j - 1], y[j]);
}
p2[n + 1] = 1e9;
for (int j = n; j > 0; j--){
p2[j] = min(p2[j + 1], y[j]);
}
for (int k: d[v]){
out[k] -= min(p1[k - 1], p2[k + 1]);
}
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);
for (int i = 1; i <= n; i++){
cout<<out[i]<<"\n";
}
}
# | 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... |