이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> ppp;
const int MAXN = 3e5;
const int MAXM = 20;
const int INF = 1e9;
int N, M, A[MAXN+10][MAXM+10];
int P[MAXM+10];
int B[MAXN+10];
ppp dp[(1<<MAXM)+10][MAXM+10];
pii operator + (pii &p, int q)
{
return {p.first+q, p.second};
}
ppp operator + (ppp &p, int q)
{
return {p.first+q, p.second+q};
}
void f(ppp &p, ppp q)
{
if(p.first<q.first)
{
if(q.first.second==p.first.second) q.first=q.second;
p={p.first, min(q.first, p.second)};
}
else
{
if(p.first.second==q.first.second) p.first=p.second;
p={q.first, min(p.first, q.second)};
}
}
int main()
{
scanf("%d%d", &N, &M);
for(int i=1; i<=N; i++) for(int j=0; j<M; j++) scanf("%d", &A[i][j]);
for(int j=0; j<M; j++)
{
int cnt=0;
for(int i=1; i<=N; i++) cnt+=A[i][j];
if(cnt<N/2) P[j]=0;
else if(cnt>N/2+1) P[j]=3;
else if(cnt==N/2) P[j]=1;
else if(cnt==N/2+1) P[j]=2;
}
for(int j=0; j<=M; j++) for(int i=0; i<(1<<M); i++) dp[i][j]={pii(INF, -1), pii(INF, -1)};
for(int i=1; i<=N; i++)
{
for(int j=0; j<M; j++) B[i]|=(A[i][j]<<j);
f(dp[B[i]][0], {pii(0, i), pii(INF, -1)});
}
for(int i=0; i<M; i++)
{
for(int j=0; j<(1<<M); j++)
{
if(P[i]==0)
{
f(dp[j][i+1], dp[j][i]+1);
f(dp[j][i+1], dp[j^(1<<i)][i]+1);
}
if(P[i]==3)
{
f(dp[j][i+1], dp[j][i]);
f(dp[j][i+1], dp[j^(1<<i)][i]);
}
if(P[i]==1)
{
if(j&(1<<i))
{
f(dp[j][i+1], dp[j][i]+1);
f(dp[j][i+1], dp[j^(1<<i)][i]+1);
}
else
{
f(dp[j][i+1], dp[j][i]);
f(dp[j][i+1], dp[j^(1<<i)][i]+1);
}
}
if(P[i]==2)
{
if(j&(1<<i))
{
f(dp[j][i+1], dp[j][i]+1);
f(dp[j][i+1], dp[j^(1<<i)][i]);
}
else
{
f(dp[j][i+1], dp[j][i]);
f(dp[j][i+1], dp[j^(1<<i)][i]);
}
}
}
}
for(int i=1; i<=N; i++)
{
if(dp[B[i]][M].first.second!=i) printf("%d\n", M-dp[B[i]][M].first.first);
else printf("%d\n", M-dp[B[i]][M].second.first);
}
}
컴파일 시 표준 에러 (stderr) 메시지
council.cpp: In function 'int main()':
council.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d%d", &N, &M);
| ~~~~~^~~~~~~~~~~~~~~~
council.cpp:46:54: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | for(int i=1; i<=N; i++) for(int j=0; j<M; j++) scanf("%d", &A[i][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... |