QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#477754#9114. Black or White 2ucup-team1231#AC ✓523ms21424kbC++143.6kb2024-07-14 09:46:472024-07-14 09:46:47

Judging History

你现在查看的是最新测评结果

  • [2024-07-14 09:46:47]
  • 评测
  • 测评结果:AC
  • 用时:523ms
  • 内存:21424kb
  • [2024-07-14 09:46:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define SZ 2999999
typedef long long ll;
#define pb push_back
int n,m,k,ans=2e9,a[2000][2000];
string rst;
void dfs(int x,int y,int tt=0,int ca=0) {
    if(ca>=ans) return;
    if(x>=n) {
        if(tt!=k) return;
        ans=min(ans,ca);
        rst.clear();
        for(int i=0;i<n;++i) {
            for(int j=0;j<m;++j) rst.pb(a[i][j]+'0');
            rst.pb('\n');
        }
        return;
    }
    if(y>=m) {
        dfs(x+1,0,tt,ca);
        return;
    }
    for(a[x][y]=0;a[x][y]<=1;++a[x][y]) {
        int caa=ca;
        if(x&&y)
            caa+=a[x][y]+a[x][y-1]+a[x-1][y]+a[x-1][y-1]==2;
        dfs(x,y+1,tt+a[x][y],caa);
    }
    a[x][y]=0;
}
string mem[50][50][50];
int col[23333];
void sol() {
    map<int,int> cc;
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j) {
            ++cc[i+j];
        }
    int R=n+m-2;
    for(int i=0;i<=R+5;++i) col[i]=-1;
    vector<pair<int,int>> s,g;
    int RR=4;
    for(int i=4;i<=R-4;i+=2) {
        s.pb({cc[i]+cc[i+1],i});
        RR=i+2;
    }
    for(int i=0;i<4;++i) g.pb({cc[i],i});
    for(int i=RR;i<=R;++i) g.pb({cc[i],i});
        // for(auto t:g) cerr<<t.first<<" "; cerr<<"|"<<endl;
        // for(auto t:s) cerr<<t.first<<" "; cerr<<endl;

    while(1) {
        random_shuffle(s.begin(),s.end());
        int u[2]={k,n*m-k},ou[2];
        for(auto c:s) {
            int cc;
            if(u[0]>=u[1]) u[cc=0]-=c.first;
            else u[cc=1]-=c.first;
            if(u[0]<0||u[1]<0) break;
            col[c.second]=col[c.second+1]=cc;
        }
        if(u[0]<0||u[1]<0) continue;
        ou[0]=u[0]; ou[1]=u[1];
        for(int uu=1;uu<=100;++uu) {
            random_shuffle(g.begin(),g.end());
            for(auto t:g) col[t.second]=-1;
            u[0]=ou[0]; u[1]=ou[1];
            for(auto c:g) {
                int cc;
                if(u[0]>=u[1]) u[cc=0]-=c.first;
                else u[cc=1]-=c.first;
                if(u[0]<0||u[1]<0) break;
                col[c.second]=cc;
            }
            if(u[0]<0||u[1]<0) continue;
            for(int i=0;i<=R;++i)
                if(col[i]==col[i+2]&&col[i]!=col[i+1]) goto nxt;
    for(int i=0;i<n;++i) {
        for(int j=0;j<m;++j) {
            putchar(col[i+j]+48);
        }
        putchar(10);
        }
            // cout<<u[0]<<" "<<u[1]<<endl;
            return;
            nxt:;
        }
    }
}
bool easysol() {
    int o[2]={k,n*m-k},ww[2]={0,0},X=0,mi=min(o[0],o[1]);
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j) a[i][j]=(i%2==0&&j%2==0&&(mi-->0)),++ww[a[i][j]];
    // cerr<<ww[0]<<","<<ww[1]<<"  "<<o[0]<<","<<o[1]<<"\n";
    if(ww[1]<=o[0]&&ww[0]<=o[1])
        swap(ww[0],ww[1]),X=1;
    if(ww[0]==o[0]&&ww[1]==o[1]) {
    for(int i=0;i<n;++i,putchar(10))
        for(int j=0;j<m;++j) putchar((a[i][j]^X)+48);
        return 1;
    }
    return 0;
}
int main() {
    for(n=1;n<=20;++n)
        for(m=1;n*m<=20;++m) {
            for(k=0;k<=n*m;++k) {
                ans=2e9;rst="";
                dfs(0,0);
                mem[n][m][k]=rst;
//                cout<<ans<<"+"<<endl<<rst<<endl;
            }
        }
    int T; cin>>T;
    while(T--) {
        n=rand()%45+1,
        m=rand()%45+1;
        k=rand()%(n*m+1);
        // n=11,m=3,k=20;
        cin>>n>>m>>k;
        //cerr<<n<<" "<<m<<" "<<k<<"\n";
        // cin>>n>>m>>k;
        if(n*m<=20) printf("%s",mem[n][m][k].c_str());
        else {
            k=n*m-k; if(!easysol()) sol();
        }
    }
}
//11 3 20

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 277ms
memory: 9196kb

input:

2
2 2 2
2 3 0

output:

00
11
000
000

result:

ok Output is valid. OK.

Test #2:

score: 0
Accepted
time: 349ms
memory: 8136kb

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
00
01
00
11
01
11
11
11
000
000
000
001
000
101
001
011
010
111
011
111
111
111
00
00
00
00
00
01
01
00
01
00
01
11
01
11
01
01
11
11
11
11
11
000
000
000
000
000
001
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
011
111
111
111
111
111
0000
0000
0000
0001
0000
0101
0...

result:

ok Output is valid. OK.

Test #3:

score: 0
Accepted
time: 434ms
memory: 19068kb

input:

162
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #4:

score: 0
Accepted
time: 433ms
memory: 20376kb

input:

163
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #5:

score: 0
Accepted
time: 443ms
memory: 20396kb

input:

165
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #6:

score: 0
Accepted
time: 523ms
memory: 20280kb

input:

1020
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #7:

score: 0
Accepted
time: 514ms
memory: 20080kb

input:

1012
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #8:

score: 0
Accepted
time: 501ms
memory: 21280kb

input:

1033
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #9:

score: 0
Accepted
time: 475ms
memory: 8000kb

input:

100000
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #10:

score: 0
Accepted
time: 333ms
memory: 7860kb

input:

100000
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #11:

score: 0
Accepted
time: 351ms
memory: 7752kb

input:

100000
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
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
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4...

output:

00
11
000
101
001
011
010
111
01
00
01
00
01
11
01
11
01
000
000
101
000
001
011
000
010
111
000
101
111
001
011
111
010
111
111
0000
0101
0001
0011
0001
1011
0011
0111
0101
1111
0000
0000
0101
0000
0001
0011
0000
0001
1011
0001
0011
0110
0000
0101
1111
0001
1011
1110
0001
1011
1111
0011
0111
1111
0...

result:

ok Output is valid. OK.

Test #12:

score: 0
Accepted
time: 303ms
memory: 21424kb

input:

3
1500 1500 2250000
1322 1322 1747684
1158 2 2316

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok Output is valid. OK.

Test #13:

score: 0
Accepted
time: 499ms
memory: 21404kb

input:

3
1500 1500 1125000
1322 1322 873842
1158 2 1158

output:

000011111100111100001111111100111111111111111100000011110011001111000000111100000000001111110000110011110000111100110011001100110011000000110000000011111100110011000011110011110000111100000000111100000011000011111111001111110000111111001100110000111111111100001111001111000000110011001111000011000011...

result:

ok Output is valid. OK.

Extra Test:

score: 0
Extra Test Passed