이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define int long long
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int a[n][m];
int b[n];
int s[m];
for(int i=0; i<m; i++) s[i] = 0;
for(int i=0; i<n; i++) {
b[i] = 0;
for(int j=0; j<m; j++) {
cin >> a[i][j];
s[j] += a[i][j];
b[i] |= (a[i][j] << j);
}
}
int cnt[(1<<m)];
int ans[(1<<m)];
for(int i=0; i<(1<<m); i++) cnt[i] = 0, ans[i] = -1;
for(int i=0; i<n; i++) cnt[b[i]]++;
pair<int,int> dp[(1<<m)][2];
for(int i=0; i<(1<<m); i++) for(int j=0; j<2; j++) dp[i][j] = {1e9, -1};
for(int i=0; i<n; i++) {
if(dp[b[i]][0].first == 0) dp[b[i]][1] = {0, i};
else dp[b[i]][0] = {0, i};
}
reverse(dp, dp+(1<<m));
for(int i=1; i<(1<<m); i++) {
if(dp[i][1].first == 0) continue;
for(int j=0; j<m; j++) {
if(i&(1<<j)) {
int tar0=dp[i^(1<<j)][0].first+1, tar1=dp[i^(1<<j)][1].first+1;
vector<pair<int,int> > w = {
{tar0,dp[i^(1<<j)][0].second},
{tar1,dp[i^(1<<j)][1].second},
dp[i][0],dp[i][1]
};
sort(w.begin(), w.end());
dp[i][0] = w[0];
for(int k=1; k<4; k++) {
if(dp[i][0].second != w[k].second) {
dp[i][1] = w[k]; break;
}
}
}
}
}
for(int i=0; i<n; i++) {
int bad = 0, base = 0;
for(int j=0; j<m; j++) {
int ss = s[j] - a[i][j];
if(ss >= n/2) base++;
if(ss == n/2) bad |= (1<<j);
}
int opt = dp[bad][0].first;
if(dp[bad][0].second == i) opt = dp[bad][1].first;
cout << base - opt << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
council.cpp: In function 'int32_t main()':
council.cpp:22:7: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
22 | int ans[(1<<m)];
| ^~~
# | 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... |