QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#483104 | #9114. Black or White 2 | ucup-team1134 | AC ✓ | 56ms | 5492kb | C++23 | 5.3kb | 2024-07-18 11:08:55 | 2024-07-18 11:08:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;
vector<string> solve(int N,int M,int K){
vector<string> S(N,string(M,'0'));
if(N==4&&M==4&&K==5){
S[0][1]=S[0][2]=S[1][0]=S[1][1]=S[2][0]='1';
return S;
}
if(N==5&&M==4&&K==9){
S[0][1]=S[0][2]=S[1][0]=S[1][1]=S[2][0]='1';
S[0][3]=S[1][2]=S[2][1]=S[3][0]='1';
return S;
}
if(N==5&&M==5&&K==12){
for(int i=0;i<N;i++){
for(int j=0;j<5-i;j++){
S[i][j]='1';
}
}
S[0][0]=S[0][1]=S[1][0]='0';
return S;
}
int sv=K;
for(int i=0;;i+=2){
int need=(3*M+1)/2;
if(K>=need){
for(int a=0;a<M;a++){
S[i][a]='1';
}
for(int a=0;a<M;a+=2){
S[i+1][a]='1';
}
K-=need;
}else if(i>=2&&K>=M){
for(int s=i;s>=1;s--) swap(S[s],S[s-1]);
for(int a=0;a<M;a++) S[0][a]='1';
K-=M;
}else{
break;
}
}
for(int i=N-1;i>=0;i-=2){
for(int j=M-1;j>=0;j-=2){
if(K){
S[i][j]='1';
K--;
}
}
}
bool f=true;
int cncn=0;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
if(S[i][j]=='1') cncn++;
}
}
assert(cncn==sv);
for(int i=0;i+1<N;i++){
for(int j=0;j+1<M;j++){
int cn=0;
cn+=(S[i][j]=='1');
cn+=(S[i][j+1]=='1');
cn+=(S[i+1][j]=='1');
cn+=(S[i+1][j+1]=='1');
assert(cn!=2);
}
}
return S;
if(N==2){
if(K%2==0){
for(int j=0;j<K/2-1;j++) S[0][j]=S[1][j]='1';
S[0][K/2-1]='1';
S[1].back()='1';
}else{
for(int j=0;j<K/2-1;j++) S[0][j]=S[1][j]='1';
S[0][K/2-1]='1';
}
return S;
}else{
}
return S;
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
/*
for(int N=3;N<=20;N++){
for(int M=2;M<=N;M++){
for(int K=0;K<=N*M/2;K++){
cout<<N<<" "<<M<<" "<<K<<endl;
solve(N,M,K);
}
}
}
*/
int Q;cin>>Q;
while(Q--){
ll N,M,K;cin>>N>>M>>K;
if(N==2&&M==2){
if(K==2){
cout<<"01\n";
cout<<"10\n";
}else{
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
if(K){
cout<<1;
K--;
}else{
cout<<0;
}
}
cout<<"\n";
}
}
}else{
bool fl=false;
if(K+K>N*M){
fl=true;
K=N*M-K;
}
bool tr=false;
if(N<M){
swap(N,M);
tr=true;
}
auto res=solve(N,M,K);
if(fl){
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
res[i][j]^=1;
}
}
}
if(tr){
for(int j=0;j<M;j++){
for(int i=0;i<N;i++){
cout<<res[i][j];
}
cout<<"\n";
}
}else{
for(int i=0;i<N;i++) cout<<res[i]<<"\n";
}
}
}
/*
for(int N=2;N<=5;N++){
for(int M=2;M<=5;M++){
vector<pair<int,vector<string>>> ans(N*M+1,mp(INF,vector<string>{}));
for(int bit=0;bit<(1<<N*M);bit++){
vector<string> S(N);
for(int i=0;i<N*M;i++){
if(bit&(1<<i)){
S[i/M]+='1';
}else{
S[i/M]+='0';
}
}
int ng=0;
for(int i=0;i+1<N;i++){
for(int j=0;j+1<M;j++){
int cn=0;
cn+=(S[i][j]=='1');
cn+=(S[i][j+1]=='1');
cn+=(S[i+1][j]=='1');
cn+=(S[i+1][j+1]=='1');
if(cn==2) ng++;
}
}
chmin(ans[__builtin_popcount(bit)],mp(ng,S));
}
cout<<N<<" "<<M<<endl;
for(auto [x,S]:ans){
for(string T:S) cout<<T<<"\n";
cout<<"\n";
}
cout<<endl;
}
}
*/
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3860kb
input:
2 2 2 2 2 3 0
output:
01 10 000 000
result:
ok Output is valid. OK.
Test #2:
score: 0
Accepted
time: 39ms
memory: 3632kb
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 01 10 11 10 11 11 000 000 000 001 000 101 110 100 111 010 111 110 111 111 00 00 00 00 00 01 01 00 01 11 10 00 10 11 10 11 11 10 11 11 11 000 000 000 000 000 001 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 111 111 110 111 111 111 0000 0000 0000 0001 0000 0101 1...
result:
ok Output is valid. OK.
Test #3:
score: 0
Accepted
time: 26ms
memory: 4804kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #4:
score: 0
Accepted
time: 28ms
memory: 4304kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #5:
score: 0
Accepted
time: 27ms
memory: 4400kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #6:
score: 0
Accepted
time: 40ms
memory: 3888kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #7:
score: 0
Accepted
time: 40ms
memory: 3688kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #8:
score: 0
Accepted
time: 40ms
memory: 3692kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #9:
score: 0
Accepted
time: 56ms
memory: 3600kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #10:
score: 0
Accepted
time: 39ms
memory: 3600kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #11:
score: 0
Accepted
time: 39ms
memory: 3636kb
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:
01 10 000 101 110 100 111 010 01 00 01 11 10 00 10 11 10 000 000 101 001 000 101 101 000 101 010 111 010 110 111 010 111 111 010 0000 0101 1100 1000 1100 1001 0011 0111 1111 1010 0001 0000 0001 0001 0000 0101 0101 0000 0101 1100 1000 1100 1100 1000 1101 0011 0111 0011 1010 1111 1010 1110 1111 1010 1...
result:
ok Output is valid. OK.
Test #12:
score: 0
Accepted
time: 11ms
memory: 5492kb
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: 14ms
memory: 5464kb
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