QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#475177 | #9114. Black or White 2 | ucup-team008# | RE | 122ms | 3824kb | C++17 | 7.6kb | 2024-07-13 12:41:29 | 2024-07-13 12:41:29 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(0) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
template<class T>
bool updmin(T& a, T b) {
if(b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool updmax(T& a, T b) {
if(b > a) {
a = b;
return true;
}
return false;
}
typedef int64_t ll;
void solve(vector<vector<int>>& g, int r, int c, int k) {
if(r > c) {
solve(g, c, r, k);
vector<vector<int>> ng(r);
for(auto& x: ng) x.resize(c);
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
ng[i][j] = g[j][i];
}
}
g.swap(ng);
return;
}
assert(r <= c);
if(k > r*c-k) {
solve(g, r, c, r*c-k);
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) g[i][j] ^= 1;
return;
}
assert(2*k <= r*c);
g.resize(r);
for(auto& x: g) x.resize(c);
if(k == 0) return;
if(k == 1) {
g[0][0] = 1;
return;
}
if(k == 2) {
g[0][0] = 1;
g[r-1][c-1] = 1;
return;
}
vector<int> diagcnt(r+c-1);
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) diagcnt[i+j]++;
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt > k) break;
if(amt == k && a != b) {
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b) g[i][j] = 1;
}
return;
}
}
}
if(k == 4) {
g[0][0] = 1;
g[0][c-1] = 1;
g[r-1][0] = 1;
g[r-1][c-1] = 1;
return;
}
// diagonal + bottom right corner
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt == k-1) {
g[r-1][c-1] = 1;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b) g[i][j] = 1;
}
return;
}
}
}
// diagonal plus 2?
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt == k-2) {
g[r-3][c-1] = 1;
g[r-1][c-3] = 1;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b) g[i][j] = 1;
}
return;
}
}
}
// diagonal plus 3?
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt == k-3) {
g[r-3][c-3] = 1;
g[r-3][c-1] = 1;
g[r-1][c-3] = 1;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b) g[i][j] = 1;
}
return;
}
}
}
// diagonal plus 4?
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt == k-4) {
g[r-5][c-1] = 1;
g[r-3][c-3] = 1;
g[r-3][c-1] = 1;
g[r-1][c-3] = 1;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b) g[i][j] = 1;
}
return;
}
}
}
// diagonal plus 5?
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt == k-5) {
g[r-5][c-1] = 1;
g[r-3][c-3] = 1;
g[r-3][c-3] = 1;
g[r-3][c-1] = 1;
g[r-1][c-3] = 1;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b) g[i][j] = 1;
}
return;
}
}
}
// diagonal plus 6?
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt == k-6) {
g[r-5][c-1] = 1;
g[r-3][c-3] = 1;
g[r-1][c-5] = 1;
g[r-3][c-3] = 1;
g[r-3][c-1] = 1;
g[r-1][c-3] = 1;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b) g[i][j] = 1;
}
return;
}
}
}
assert(false);
// diagonal minus one
for(int a = 0; a < sz(diagcnt); a++) {
int amt = 0;
for(int b = a; b < sz(diagcnt); b++) {
amt += diagcnt[b];
if(amt == k-1) {
g[r-1][c-1] = 1;
int need = k;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(a <= i+j && i+j <= b && need > 0) {
g[i][j] = 1;
need--;
}
}
return;
}
}
}
assert(false);
}
void rsolve() {
int r, c, k;
cin >> r >> c >> k;
vector<vector<int>> g;
solve(g, r, c, k);
int tot = 0;
for(int i = 0; i < r; i++) {
for(int j = 0; j < c; j++) {
cout << g[i][j];
tot += g[i][j];
}
cout << "\n";
}
assert(tot == k);
}
void solve() {
int t;
cin >> t;
while(t--) rsolve();
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
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: 122ms
memory: 3636kb
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 101 000 101 010 111 010 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: -100
Runtime Error
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 101 000 101 010 111 010 001 011 111 011 111 110 1000 0001 1100 1000 0110 1100 0011 0111 0111 1110 1000 0000 0001 1100 1000 0000 1001 0000 1001 0110 1100 1000 1110 1100 1000 1001 0011 0111 0110 1111 0110 0011 0111 1111 0...