QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#535811 | #9114. Black or White 2 | synonym | AC ✓ | 160ms | 27796kb | C++17 | 3.2kb | 2024-08-28 15:10:33 | 2024-08-28 15:10:35 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
const int mxn=2e3;
void check();
int n,m,k,fl,nm;
int g[mxn][mxn];
void solve447() {
g[0][0]=g[0][1]=g[0][2]=g[0][3]=g[1][1]=g[1][3]=g[3][3]=1;
}
void solve2() {
if (k%2) {
for (int i=0; i<m; i++) {
if (k==0) break;
g[0][i] = 1; k--; if (k==0) break;
g[1][i] = 1; k--; if (k==0) break;
}
} else {
if (k==0) return;
g[0][m-1] = 1; k--;
for (int i=0; i<m; i++) {
if (k==0) break;
g[0][i] = 1; k--; if (k==0) break;
g[1][i] = 1; k--; if (k==0) break;
}
}
}
void solve3() {
if (k%3==0 && k) {
g[0][m-1] = 1; k--;
}
int ok = k;
for (int i=0; k; i++) {
if (!k) break;
if (ok%3==1) {
g[1][i] = 1; k--;
if (!k) break;
g[0][i] = 1; k--;
g[2][i] = 1; k--;
if (!k) break;
} else {
g[0][i] = 1; k--;
g[2][i] = 1; k--;
if (!k) break;
g[1][i] = 1; k--;
if (!k) break;
}
}
}
void solvek2() {
g[0][0] = g[n-1][m-1] = 1;
}
void solven() {
// swap(n,m); nm = !nm;
for (int i=0; i<=n; i++) {
for (int j=0; j<=m; j++) {
g[i][j] = 0;
}
}
int c = 0;
while (k >= 2*n) {
for (int i=0; i<n; i++) {
g[i][c] = 1; k--;
}
c++;
}
if (k >= n) {
for (int i=0; i<n; i+=2) {
g[i][c] = 1; k--;
}
}
if (2*k <= n) {
for (int i=0; k; i+=2) {
g[i][m-1] = 1; k--;
}
return;
}
int fff = 0;
if (k%3==2) {
fff = 1; k--;
}
int sp = 0;
if (k%3==1) {
g[0][m-1] = 1; sp=1; k--;
}
for (int i=sp; k; i++) {
g[i][m-1] = 1; k--;
if (!k) break;
if (i%2==sp%2) {
g[i][m-2] = 1; k--;
}
}
if (fff) {
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
if (g[i][j]) continue;
int su=0;
su += g[i+1][j+1]+g[i+1][j]+(j?g[i+1][j-1]:0);
su += g[i][j+1]+g[i][j+1]+(j?g[i][j-1]:0);
if (i) su += g[i-1][j+1]+g[i-1][j]+(j?g[i-1][j-1]:0);
if (!su) {
// cout<<i<<" "<<j<<" "<<su<<endl;
fff = 0;
g[i][j] = 1;
return;
}
}
}
assert(0);
}
}
int ok;
void solve() {
cin>>n>>m>>k; ok = k;
if (2*k > n*m) {
fl = 1;
k = n*m-k;
} else fl = 0;
if (n>m) {
nm = 1;
swap(n,m);
} else nm = 0;
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) g[i][j]=0;
}
if (n==3 && m==3 && k==4) {
g[0][0] = g[0][1] = g[0][2] = g[1][1] = 1;
} else {
if (n==4&&m==4&&k==7) {
solve447();
} else if (n==2) {
solve2();
} else if (n==3) {
solve3();
} else if (k==2) {
solvek2();
} else {
solven();
}
}
if (fl) {
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
g[i][j] = 1-g[i][j];
}
}
}
int aa = 0;
if (nm) {
for (int j=0; j<m; j++) {
for (int i=0; i<n; i++) {
cout<<g[i][j]<<"";
aa+=g[i][j];
}
cout<<"\n";
}
} else {
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
cout<<g[i][j]<<"";
aa+=g[i][j];
}
cout<<"\n";
}
}
cout<<"\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int t; cin>>t;
for (int i=0; i<t; i++) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
2 2 2 2 2 3 0
output:
11 00 000 000
result:
ok Output is valid. OK.
Test #2:
score: 0
Accepted
time: 155ms
memory: 3676kb
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 11 00 01 11 11 11 000 000 100 000 101 000 110 100 010 111 011 111 111 111 00 00 00 10 00 00 10 00 10 11 10 00 01 11 01 01 11 11 11 11 11 000 000 000 000 100 000 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 111 011 111 111 111 111 00...
result:
ok Output is valid. OK.
Test #3:
score: 0
Accepted
time: 146ms
memory: 21548kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #4:
score: 0
Accepted
time: 144ms
memory: 15488kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #5:
score: 0
Accepted
time: 150ms
memory: 17580kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #6:
score: 0
Accepted
time: 139ms
memory: 3832kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #7:
score: 0
Accepted
time: 147ms
memory: 3896kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #8:
score: 0
Accepted
time: 140ms
memory: 3816kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #9:
score: 0
Accepted
time: 160ms
memory: 3708kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #10:
score: 0
Accepted
time: 68ms
memory: 3616kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #11:
score: 0
Accepted
time: 64ms
memory: 3628kb
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:
11 00 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 100 000 100 101 000 100 111 010 000 000 101 111 010 111 011 011 111 011 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1000 1100 1000 1100 1000 1100 1101 1000 1100 0011 0111 0011 0111 00...
result:
ok Output is valid. OK.
Test #12:
score: 0
Accepted
time: 144ms
memory: 27224kb
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: 135ms
memory: 27796kb
input:
3 1500 1500 1125000 1322 1322 873842 1158 2 1158
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
ok Output is valid. OK.
Extra Test:
score: 0
Extra Test Passed