QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#486846 | #9114. Black or White 2 | ucup-team159 | AC ✓ | 144ms | 16120kb | C++23 | 4.9kb | 2024-07-22 07:29:57 | 2024-07-22 07:29:58 |
Judging History
answer
#line 1 "B.cpp"
// #pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")
#line 2 "/home/sigma/comp/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
if(x<y){ x=y; return true; }
return false;
}
template<class T,class U> bool chmin(T& x, U y){
if(y<x){ x=y; return true; }
return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
o<<"{";
for(const T& v:vc) o<<v<<",";
o<<"}";
return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ~ ";
dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \
for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
template<class D> D divFloor(D a, D b){
return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
/*
x 0 1 2 3 4 5 6 7 8 9
bsr(x) -1 0 1 1 2 2 2 2 3 3
最上位bit
*/
int bsr(int x){
return x == 0 ? -1 : 31 ^ __builtin_clz(x);
}
int bsr(uint x){
return x == 0 ? -1 : 31 ^ __builtin_clz(x);
}
int bsr(ll x){
return x == 0 ? -1 : 63 ^ __builtin_clzll(x);
}
int bsr(ull x){
return x == 0 ? -1 : 63 ^ __builtin_clzll(x);
}
/*
x 0 1 2 3 4 5 6 7 8 9
bsl(x) -1 0 1 0 2 0 1 0 3 0
最下位bit
*/
int bsl(int x){
if(x==0) return -1;
return __builtin_ctz(x);
}
int bsl(uint x){
if(x==0) return -1;
return __builtin_ctz(x);
}
int bsl(ll x){
if(x==0) return -1;
return __builtin_ctzll(x);
}
int bsl(ull x){
if(x==0) return -1;
return __builtin_ctzll(x);
}
#line 5 "B.cpp"
void solve(int H, int W, int K){
bool flipped = false;
bool flipHW = false;
if(K > H*W-K){
K = H*W-K; flipped = true;
}
if(H < W){
swap(H,W); flipHW = true;
}
VV<int> A(H,V<int>(W));
if(H == 4 && W == 4 && K == 5){
A[0][0] = A[0][1] = A[1][0] = A[3][0] = A[3][2] = 1;
}else if(H == 5 && W == 4 && K == 9){
A[0][0] = A[1][0] = A[2][0] = A[3][0] = A[4][0] = A[0][1] = A[2][1] = A[4][1] = A[0][3] = 1;
}else if(H == 5 && W == 5 && K == 12){
rep(i,2) rep(j,5) A[i][j] = 1;
A[2][1] = A[2][3] = 1;
}else{
int m = (W+1)/2;
if(K <= m){
rep(j,K) A[0][j*2] = 1;
}else{
int q = (K-m)/W;
int r = (K-m)%W;
rep(i,q) rep(j,W) A[i][j] = 1;
rep(j,m) A[q][j*2] = 1;
for(int i=H-1;i>=0;i-=2) for(int j=0;j<W;j+=2){
if(r == 0) goto done;
A[i][j] = 1; r--;
}
done:{}
}
}
if(flipped){
K = H*W-K;
rep(i,H) rep(j,W) A[i][j] ^= 1;
}
if(flipHW){
VV<int> B(W,V<int>(H));
rep(i,H) rep(j,W) B[j][i] = A[i][j];
A = B; swap(H,W);
}
#ifdef LOCAL
if(!(H == 2 && W == 2 && K == 2)){
rep(i,H-1) rep(j,W-1){
if(A[i][j] + A[i][j+1] + A[i+1][j] + A[i+1][j+1] == 2){
show(H);show(W);show(K);show(A);
assert(false);
}
}
}
{
int s = 0;
rep(i,H) rep(j,W) s += A[i][j];
assert(s == K);
}
#else
rep(i,H){
rep(j,W) cout << A[i][j];
cout << '\n';
}
#endif
}
void TEST(){
for(int H=2;H<=20;H++) for(int W=2;W<=20;W++){
rep(K,H*W+1){
solve(H,W,K);
}
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !!
cout << fixed << setprecision(20);
// TEST();
int T; cin >> T;
while(T--){
int H,W,K; cin >> H >> W >> K;
solve(H,W,K);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
2 2 2 2 2 3 0
output:
10 10 000 000
result:
ok Output is valid. OK.
Test #2:
score: 0
Accepted
time: 110ms
memory: 3616kb
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 10 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 100 000 000 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 011 111 111 111 111 111 0000 0000 1000 0000 1001 0000 1...
result:
ok Output is valid. OK.
Test #3:
score: 0
Accepted
time: 92ms
memory: 16120kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #4:
score: 0
Accepted
time: 102ms
memory: 14052kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #5:
score: 0
Accepted
time: 92ms
memory: 13312kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #6:
score: 0
Accepted
time: 106ms
memory: 3944kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #7:
score: 0
Accepted
time: 109ms
memory: 3984kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #8:
score: 0
Accepted
time: 110ms
memory: 4172kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #9:
score: 0
Accepted
time: 144ms
memory: 3604kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #10:
score: 0
Accepted
time: 61ms
memory: 3668kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #11:
score: 0
Accepted
time: 56ms
memory: 3800kb
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:
10 10 101 000 110 100 010 111 10 00 10 11 10 00 01 11 01 101 000 000 101 000 100 101 000 101 010 111 010 010 111 011 010 111 111 1001 0000 1100 1000 1101 1000 0011 0111 0110 1111 1000 0000 1000 1001 0000 1000 1001 0000 1001 1100 1000 1100 1101 1000 1100 0011 0111 0011 0110 1111 0110 0110 1111 0111 0...
result:
ok Output is valid. OK.
Test #12:
score: 0
Accepted
time: 90ms
memory: 12188kb
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: 92ms
memory: 12044kb
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