QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#483367 | #9114. Black or White 2 | ucup-team1525# | WA | 460ms | 24672kb | C++20 | 5.8kb | 2024-07-18 16:20:14 | 2024-07-18 16:20:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int t,n,m,k;
const int N=1505;
int a[N][N];
// int f[12][100][1<<8],fr[10][100][1<<8];
// int n,m,k;
// int calc(int x,int y)
// {
// int sum=0;
// for (int i=0;i<n-1;++i)
// {
// int o=(x>>i)&1,p=(x>>(i+1))&1,q=(y>>i)&1,r=(y>>(i+1))&1;
// if (o+p+q+r==2)
// ++sum;
// }
// return sum;
// }
const int inf=1e9+7;
int f[65][70][1<<9],fr[65][70][1<<9];
int prea[9][9][70][9][9];
void prework(int n,int m,int k,int a[9][9])
{
for (int i=1;i<=n*m;++i)
for (int j=0;j<=k;++j)
for (int l=0;l<(1<<(n+1));++l)
f[i][j][l]=inf;
for (int i=0;i<(1<<n);++i)
if (__builtin_popcount(i)<=k)
f[n][k-__builtin_popcount(i)][i]=0;
int mask=(1<<(n+1))-1;
for (int i=2;i<=m;++i)
{
for (int j=1;j<=n;++j)
{
for (int l=0;l<=k;++l)
for (int o=0;o<(1<<(n+1));++o)
{
int id=(i-1)*n+j;
if (f[id-1][l][o]<inf)
{
int tmp=o&1;
if ((o>>n)&1) ++tmp;
if ((o>>(n-1)&1)) ++tmp;
if (j==1)
tmp=-1;
if (l!=0)
{
if (f[id][l-1][((o<<1)&mask)|1]>f[id-1][l][o]+(tmp==1?1:0))
{
f[id][l-1][((o<<1)&mask)|1]=f[id-1][l][o]+(tmp==1?1:0);
fr[id][l-1][((o<<1)&mask)|1]=o;
}
}
if (f[id][l][((o<<1)&mask)]>f[id-1][l][o]+(tmp==2?1:0))
{
f[id][l][((o<<1)&mask)]=f[id-1][l][o]+(tmp==2?1:0);
fr[id][l][((o<<1)&mask)]=o;
}
}
}
// for (int l=0;l<=k;++l)
// for (int o=0;o<(1<<n);++o)
}
}
int mnp=0;
for (int i=1;i<(1<<(n+1));++i)
if (f[n*m][0][i]<f[n*m][0][mnp])
mnp=i;
int s=0;
for (int i=m;i>=2;--i)
for (int j=n;j>=1;--j)
{
a[i][j]=mnp&1;
mnp=fr[(i-1)*n+j][s][mnp];
s+=a[i][j];
}
for (int i=n;i>=1;--i)
{
a[1][i]=mnp&1;
mnp>>=1;
}
}
void solve()
{
scanf("%d%d%d",&n,&m,&k);
int inv=0,trp=0;
if (k>n*m/2)
{
k=n*m-k;
inv=1;
}
if (n>m)
{
swap(n,m);
trp=1;
}
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
a[i][j]=0;
if (m<=8)
{
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
a[i][j]=prea[n][m][k][i][j];
}
else
{
if (k>=2*n)
{
int p=(k-(n+1)/2)/n+1;
int sum=p*n+(n+1)/2;
if (p==3&&k<3*n)
{
k-=(n+1)/2;
for (int j=1;j<=n;j+=2)
a[j][m]=1;
p=(k-(n+1)/2)/n+1;
sum=p*n+(n+1)/2;
}
for (int i=1;i<=n;++i)
for (int j=1;j<=p;++j)
{
a[i][j]=1;
// if (sum>=k&&i%2==1&&j%2==1)
// {
// --sum;
// a[i][j]=0;
// }
}
for (int j=1;j<=p;++j)
for (int i=1;i<=n;++i)
if (sum>k&&i%2==1&&j%2==1)
{
--sum;
a[i][j]=0;
}
for (int i=1;i<=n;++i)
if (i%2==1)
a[i][p+1]=1;
}
else
{
int sum=0;
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
if (i%2==1&&j%2==1&&k!=sum)
{
++sum;
a[i][j]=1;
}
// if (sum!=k)
// {u
// int inf=1e9+7;u
// for (int i=1;i<=um;++i)
// for (int j=0;j<=k;++j)
// for (int l=0;l<(1<<n);++l)
// f[i][j][l]=inf;
// for (int i=0;i<(1<<n);++i)
// if (__builtin_popcount(i)<=k)
// f[1][k-__builtin_popcount(i)][i]=0;
// for (int i=1;i<m;++i)
// for (int j=0;j<=k;++j)
// for (int l=0;l<(1<<n);++l)
// if (f[i][j][l]<inf)
// for
// }
// for (int i=1;i<=n;++i)
// for (int j=1;j<=m;++j)
// if (a[i][j]==0&&k!=0)
// {
// --k;
// a[i][j]=1;
// }
}
}
if (inv)
{
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
a[i][j]=!a[i][j];
}
if (trp)
{
for (int i=1;i<=m;++i)
{
for (int j=1;j<=n;++j)
printf("%d",a[j][i]);
puts("");
}
}
else
{
for (int i=1;i<=n;++i)
{
for (int j=1;j<=m;++j)
printf("%d",a[i][j]);
puts("");
}
}
}
int main()
{
for (int i=2;i<=8;++i)
for (int j=i;j<=8;++j)
for (int k=0;k<=i*j;++k)
prework(i,j,k,prea[i][j][k]);
scanf("%d",&t);
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 311ms
memory: 22464kb
input:
2 2 2 2 2 3 0
output:
10 01 000 000
result:
ok Output is valid. OK.
Test #2:
score: -100
Wrong Answer
time: 460ms
memory: 24672kb
input:
27520 2 2 0 2 2 1 2 2 2 2 2 3 2 2 4 2 3 0 2 3 1 2 3 2 2 3 3 2 3 4 2 3 5 2 3 6 3 2 0 3 2 1 3 2 2 3 2 3 3 2 4 3 2 5 3 2 6 3 3 0 3 3 1 3 3 2 3 3 3 3 3 4 3 3 5 3 3 6 3 3 7 3 3 8 3 3 9 2 4 0 2 4 1 2 4 2 2 4 3 2 4 4 2 4 5 2 4 6 2 4 7 2 4 8 3 4 0 3 4 1 3 4 2 3 4 3 3 4 4 3 4 5 3 4 6 3 4 7 3 4 8 3 4 9 3 4 10...
output:
00 00 10 00 10 01 01 11 11 11 000 000 100 000 100 000 110 100 011 111 011 111 111 111 00 00 00 10 00 00 10 00 00 11 10 00 01 11 11 01 11 11 11 11 11 000 000 000 100 000 000 101 000 000 110 100 000 111 010 000 000 101 111 001 011 111 010 111 111 011 111 111 111 111 111 0000 0000 1000 0000 1000 0000 1...
result:
wrong answer The number of black cell is not K