QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#538130 | #9114. Black or White 2 | nhuang685 | AC ✓ | 191ms | 28232kb | C++23 | 3.2kb | 2024-08-31 04:23:50 | 2024-08-31 04:23:51 |
Judging History
answer
/**
* @author n685
* @brief
* @date 2024-08-26 21:09:43
*
*
*/
#include "bits/stdc++.h"
#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbg_proj(...) 420
#define dbg_rproj(...) 420420
void nline() {}
void bar() {}
void start_clock() {}
void end_clock() {}
#endif
namespace io {
template <class T> T read() {
T val;
if constexpr (std::is_array_v<T>) {
for (auto &v : val) {
v = read<T::value_type>();
}
} else {
std::cin >> val;
}
return val;
}
template <class T, class U, class... Args> std::tuple<T, U, Args...> read() {
T l = read<T>();
return std::tuple_cat(
std::tuple{std::move(l)}, std::tuple{read<U, Args...>()}
);
}
// for rv::iota | rv::transform
template <class T> T read_i(int /**/) { return read<T>(); }
template <class T, class U, class... Args>
std::tuple<T, U, Args...> read_i(int /**/) {
return read<T, U, Args...>();
}
} // namespace io
std::vector<std::vector<bool>> gen(int n, int m, int k) {
if (n == 3 && m == 4 && k == 5) {
return {
{false, true, true, false},
{true, true, false, false},
{true, false, false, false}
};
}
if (n == 4 && m == 4 && k == 8) {
return {
{true, true, true, true},
{true, true, false, true},
{true, false, false, false},
{false, false, false, false}
};
}
if (n == 5 && m == 6 && k == 14) {
return {
{true, true, true, true, false, true},
{true, true, true, false, false, false},
{true, true, false, false, false, true},
{true, false, false, false, false, false},
{false, false, false, true, false, true}
};
}
const int K = k;
std::vector<std::vector<std::pair<int, int>>> loc(n + m - 1);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
loc[i + j].emplace_back(i, j);
}
}
std::vector ans(n, std::vector<bool>(m));
int mx = 0;
for (int i = 0; i < n + m - 1; ++i) {
if (k >= std::ssize(loc[i])) {
mx = i;
for (auto [a, b] : loc[i]) {
ans[a][b] = true;
}
k -= static_cast<int>(loc[i].size());
} else {
break;
}
}
for (int i = 0; i < n && k > 0; ++i) {
for (int j = 0; j < m && k > 0; ++j) {
if ((n - 1 - i) % 2 == 0 && (m - 1 - j) % 2 == 0 && i + j >= mx + 3) {
ans[i][j] = true;
--k;
}
}
}
if (k > 0) {
dbg(n, m, K);
}
return ans;
}
void solve() {
const auto [n, m, k] = io::read<int, int, int>();
if (n == 2 && m == 2 && k == 2) {
std::cout << "10\n";
std::cout << "01\n";
return;
}
bool rot = n > m;
bool fl = k > n * m / 2;
std::vector<std::vector<bool>> ans =
gen(std::min(n, m), std::max(n, m), std::min(k, n * m - k));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
bool val = fl ^ (rot ? ans[j][i] : ans[i][j]);
std::cout << val;
}
std::cout << '\n';
}
#ifdef LOCAL
std::cout << '\n';
#endif
}
int main() {
#ifndef LOCAL
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int t;
std::cin >> t;
for (int i = 0; i < t; ++i) {
// dbg(i + 1);
solve();
// bar();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
2 2 2 2 2 3 0
output:
10 01 000 000
result:
ok Output is valid. OK.
Test #2:
score: 0
Accepted
time: 173ms
memory: 3860kb
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 001 110 100 011 110 011 111 111 111 00 00 00 10 00 00 10 00 01 11 10 00 01 11 10 01 11 11 11 11 11 000 000 000 100 000 000 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 011 111 111 111 111 111 0000 0000 1000 0000 1000 0001 1...
result:
ok Output is valid. OK.
Test #3:
score: 0
Accepted
time: 124ms
memory: 20408kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #4:
score: 0
Accepted
time: 128ms
memory: 15736kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #5:
score: 0
Accepted
time: 125ms
memory: 15096kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #6:
score: 0
Accepted
time: 173ms
memory: 3936kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #7:
score: 0
Accepted
time: 172ms
memory: 4272kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #8:
score: 0
Accepted
time: 173ms
memory: 3844kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #9:
score: 0
Accepted
time: 191ms
memory: 3640kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #10:
score: 0
Accepted
time: 74ms
memory: 3552kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #11:
score: 0
Accepted
time: 78ms
memory: 3556kb
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 01 100 001 110 100 011 110 10 00 01 11 10 00 01 11 10 100 000 001 110 100 000 110 100 001 001 011 110 001 011 111 011 111 110 1000 0001 1100 1000 1100 1001 0011 0111 0111 1110 1001 0000 0000 1100 1000 0000 1100 1000 0001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0011 0111 1110 0011 0111 1111 0...
result:
ok Output is valid. OK.
Test #12:
score: 0
Accepted
time: 121ms
memory: 28232kb
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: 121ms
memory: 28232kb
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