Submission #60797388
Source Code Expand
#line 1 "main.cpp"
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
// input output utils
namespace siro53_io {
// https://maspypy.github.io/library/other/io_old.hpp
struct has_val_impl {
template <class T>
static auto check(T &&x) -> decltype(x.val(), std::true_type{});
template <class T> static auto check(...) -> std::false_type;
};
template <class T>
class has_val : public decltype(has_val_impl::check<T>(std::declval<T>())) {
};
// debug
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void dump(const T t) {
cerr << t;
}
template <class T, enable_if_t<is_floating_point<T>::value, int> = 0>
void dump(const T t) {
cerr << t;
}
template <class T, typename enable_if<has_val<T>::value>::type * = nullptr>
void dump(const T &t) {
cerr << t.val();
}
void dump(__int128_t n) {
if(n == 0) {
cerr << '0';
return;
} else if(n < 0) {
cerr << '-';
n = -n;
}
string s;
while(n > 0) {
s += (char)('0' + n % 10);
n /= 10;
}
reverse(s.begin(), s.end());
cerr << s;
}
void dump(const string &s) { cerr << s; }
void dump(const char *s) {
int n = (int)strlen(s);
for(int i = 0; i < n; i++) cerr << s[i];
}
template <class T1, class T2> void dump(const pair<T1, T2> &p) {
cerr << '(';
dump(p.first);
cerr << ',';
dump(p.second);
cerr << ')';
}
template <class T> void dump(const vector<T> &v) {
cerr << '{';
for(int i = 0; i < (int)v.size(); i++) {
dump(v[i]);
if(i < (int)v.size() - 1) cerr << ',';
}
cerr << '}';
}
template <class T> void dump(const set<T> &s) {
cerr << '{';
for(auto it = s.begin(); it != s.end(); it++) {
dump(*it);
if(next(it) != s.end()) cerr << ',';
}
cerr << '}';
}
template <class Key, class Value> void dump(const map<Key, Value> &mp) {
cerr << '{';
for(auto it = mp.begin(); it != mp.end(); it++) {
dump(*it);
if(next(it) != mp.end()) cerr << ',';
}
cerr << '}';
}
template <class Key, class Value>
void dump(const unordered_map<Key, Value> &mp) {
cerr << '{';
for(auto it = mp.begin(); it != mp.end(); it++) {
dump(*it);
if(next(it) != mp.end()) cerr << ',';
}
cerr << '}';
}
template <class T> void dump(const deque<T> &v) {
cerr << '{';
for(int i = 0; i < (int)v.size(); i++) {
dump(v[i]);
if(i < (int)v.size() - 1) cerr << ',';
}
cerr << '}';
}
template <class T> void dump(queue<T> q) {
cerr << '{';
while(!q.empty()) {
dump(q.front());
if((int)q.size() > 1) cerr << ',';
q.pop();
}
cerr << '}';
}
void debug_print() { cerr << endl; }
template <class Head, class... Tail>
void debug_print(const Head &h, const Tail &...t) {
dump(h);
if(sizeof...(Tail)) dump(' ');
debug_print(t...);
}
// print
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void print_single(const T t) {
cout << t;
}
template <class T, enable_if_t<is_floating_point<T>::value, int> = 0>
void print_single(const T t) {
cout << t;
}
template <class T, typename enable_if<has_val<T>::value>::type * = nullptr>
void print_single(const T t) {
cout << t.val();
}
void print_single(__int128_t n) {
if(n == 0) {
cout << '0';
return;
} else if(n < 0) {
cout << '-';
n = -n;
}
string s;
while(n > 0) {
s += (char)('0' + n % 10);
n /= 10;
}
reverse(s.begin(), s.end());
cout << s;
}
void print_single(const string &s) { cout << s; }
void print_single(const char *s) {
int n = (int)strlen(s);
for(int i = 0; i < n; i++) cout << s[i];
}
template <class T1, class T2> void print_single(const pair<T1, T2> &p) {
print_single(p.first);
cout << ' ';
print_single(p.second);
}
template <class T> void print_single(const vector<T> &v) {
for(int i = 0; i < (int)v.size(); i++) {
print_single(v[i]);
if(i < (int)v.size() - 1) cout << ' ';
}
}
template <class T> void print_single(const set<T> &s) {
for(auto it = s.begin(); it != s.end(); it++) {
print_single(*it);
if(next(it) != s.end()) cout << ' ';
}
}
template <class T> void print_single(const deque<T> &v) {
for(int i = 0; i < (int)v.size(); i++) {
print_single(v[i]);
if(i < (int)v.size() - 1) cout << ' ';
}
}
template <class T> void print_single(queue<T> q) {
while(!q.empty()) {
print_single(q.front());
if((int)q.size() > 1) cout << ' ';
q.pop();
}
}
void print() { cout << '\n'; }
template <class Head, class... Tail>
void print(const Head &h, const Tail &...t) {
print_single(h);
if(sizeof...(Tail)) print_single(' ');
print(t...);
}
// input
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void input_single(T &t) {
cin >> t;
}
template <class T, enable_if_t<is_floating_point<T>::value, int> = 0>
void input_single(T &t) {
cin >> t;
}
template <class T, typename enable_if<has_val<T>::value>::type * = nullptr>
void input_single(T &t) {
cin >> t;
}
void input_single(__int128_t &n) {
string s;
cin >> s;
if(s == "0") {
n = 0;
return;
}
bool is_minus = false;
if(s[0] == '-') {
s = s.substr(1);
is_minus = true;
}
n = 0;
for(int i = 0; i < (int)s.size(); i++) n = n * 10 + (int)(s[i] - '0');
if(is_minus) n = -n;
}
void input_single(string &s) { cin >> s; }
template <class T1, class T2> void input_single(pair<T1, T2> &p) {
input_single(p.first);
input_single(p.second);
}
template <class T> void input_single(vector<T> &v) {
for(auto &e : v) input_single(e);
}
void input() {}
template <class Head, class... Tail> void input(Head &h, Tail &...t) {
input_single(h);
input(t...);
}
}; // namespace siro53_io
#ifdef DEBUG
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debug_print(__VA_ARGS__)
#else
#define debug(...) (void(0))
#endif
// io setup
struct Setup {
Setup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __Setup;
using namespace siro53_io;
// types
using ll = long long;
using i128 = __int128_t;
// input macros
#define INT(...) \
int __VA_ARGS__; \
input(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
input(__VA_ARGS__)
#define STRING(...) \
string __VA_ARGS__; \
input(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
input(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
input(__VA_ARGS__)
#define LD(...) \
long double __VA_ARGS__; \
input(__VA_ARGS__)
#define UINT(...) \
unsigned int __VA_ARGS__; \
input(__VA_ARGS__)
#define ULL(...) \
unsigned long long __VA_ARGS__; \
input(__VA_ARGS__)
#define VEC(name, type, len) \
vector<type> name(len); \
input(name);
#define VEC2(name, type, len1, len2) \
vector name(len1, vector<type>(len2)); \
input(name);
// other macros
// https://trap.jp/post/1224/
#define OVERLOAD3(_1, _2, _3, name, ...) name
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define REP1(i, n) for(int i = 0; i < int(n); i++)
#define REP2(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(...) OVERLOAD3(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(RALL(v))
#define UNIQUE(v) \
sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()), v.shrink_to_fit()
#define REV(v) reverse(ALL(v))
#define SZ(v) ((int)(v).size())
#define MIN(v) (*min_element(ALL(v)))
#define MAX(v) (*max_element(ALL(v)))
// util const
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
constexpr int MOD2 = 998244353;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// util functions
void Case(int i) { cout << "Case #" << i << ": "; }
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
template <class T> inline bool chmax(T &a, T b) {
return (a < b ? a = b, true : false);
}
template <class T> inline bool chmin(T &a, T b) {
return (a > b ? a = b, true : false);
}
template <class T, int dim>
auto make_vector_impl(vector<int>& sizes, const T &e) {
if constexpr(dim == 1) {
return vector(sizes[0], e);
} else {
int n = sizes[dim - 1];
sizes.pop_back();
return vector(n, make_vector_impl<T, dim - 1>(sizes, e));
}
}
template <class T, int dim>
auto make_vector(const int (&sizes)[dim], const T &e = T()) {
vector<int> s(dim);
for(int i = 0; i < dim; i++) s[i] = sizes[dim - i - 1];
return make_vector_impl<T, dim>(s, e);
}
vector<int> iota_gen(int n, int start = 0) {
vector<int> ord(n);
iota(ord.begin(), ord.end(), start);
return ord;
}
template<typename T>
vector<int> ord_sort(const vector<T>& v, bool greater = false) {
auto ord = iota_gen((int)v.size());
sort(ALL(ord), [&](int i, int j) {
if(greater) return v[i] > v[j];
return v[i] < v[j];
});
return ord;
}
#pragma endregion Macros
#line 2 "/home/siro53/kyo-pro/compro_library/data-structure/imos2D.hpp"
#line 5 "/home/siro53/kyo-pro/compro_library/data-structure/imos2D.hpp"
template <typename T>
class imos2D {
public:
int H, W;
imos2D() = default;
explicit imos2D(int H, int W): H(H), W(W), imos(H + 1, std::vector<T>(W + 1, 0)), isBuilt(false) {}
void add(int li, int lj, int ri, int rj, T val) {
assert(0 <= li and li < H);
assert(li <= ri and ri <= H);
assert(0 <= lj and lj < W);
assert(lj <= rj and rj <= W);
imos[li][lj] += val;
imos[li][rj] -= val;
imos[ri][lj] -= val;
imos[ri][rj] += val;
}
void build() {
for(int i = 0; i <= H; i++) {
for(int j = 1; j <= W; j++) {
imos[i][j] += imos[i][j - 1];
}
}
for(int j = 0; j <= W; j++) {
for(int i = 1; i <= H; i++) {
imos[i][j] += imos[i - 1][j];
}
}
isBuilt = true;
}
inline std::vector<T>& operator[](int i) {
assert(isBuilt);
return imos[i];
}
private:
std::vector<std::vector<T>> imos;
bool isBuilt;
};
#line 2 "/home/siro53/kyo-pro/compro_library/data-structure/sum2D.hpp"
#line 5 "/home/siro53/kyo-pro/compro_library/data-structure/sum2D.hpp"
template <typename T> class sum2D {
public:
sum2D() = default;
explicit sum2D(int height, int width)
: sum(height + 1, std::vector<T>(width + 1, 0)), isBuilt(false) {}
void add(int row, int column, T val) {
assert(0 <= row + 1 && row + 1 < (int)sum.size());
assert(0 <= column + 1 && column + 1 < (int)sum[0].size());
sum[row + 1][column + 1] += val;
}
void build() {
for(int i = 1; i < (int)sum.size(); i++) {
for(int j = 1; j < (int)sum[0].size(); j++) {
sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
}
}
isBuilt = true;
}
T get_sum(int row_l, int row_r, int column_l, int column_r) const {
assert(row_l <= row_r);
assert(column_l <= column_r);
assert(isBuilt);
return (sum[row_r][column_r] - sum[row_l][column_r] -
sum[row_r][column_l] + sum[row_l][column_l]);
}
private:
std::vector<std::vector<T>> sum;
bool isBuilt;
};
#line 2 "/home/siro53/kyo-pro/compro_library/math/F2.hpp"
#line 7 "/home/siro53/kyo-pro/compro_library/math/F2.hpp"
template<int MAX_WIDTH>
class BitMatrix {
public:
int H, W;
BitMatrix(): H(1), W(1), mat(1) {
assert(W <= MAX_WIDTH);
}
BitMatrix(int H, int W): H(H), W(W), mat(H) {
assert(W <= MAX_WIDTH);
}
inline std::bitset<MAX_WIDTH>& operator[](int i) { return mat[i]; }
// 掃き出し法
// https://drken1215.hatenablog.com/entry/2019/03/20/202800
int row_reduction(vector<int>& b) {
assert((int)b.size() == H);
int rank = 0;
for(int j = 0; j < W; j++) {
int pivot = -1;
for(int i = rank; i < H; i++) {
if(mat[i][j]) {
pivot = i;
break;
}
}
if(pivot == -1) continue;
std::swap(mat[pivot], mat[rank]);
std::swap(b[pivot], b[rank]);
for(int i = 0; i < H; i++) {
if(i != rank and mat[i][j]) {
mat[i] ^= mat[rank];
b[i] ^= b[rank];
}
}
rank++;
}
return rank;
}
// 掃き出し法
// https://drken1215.hatenablog.com/entry/2019/03/20/202800
int row_reduction() {
std::vector<int> b(H, 0);
return row_reduction(b);
}
private:
std::vector<std::bitset<MAX_WIDTH>> mat;
};
// {rank, Ax = bの解のうち1つ} を返す
// 解なしの場合は {-1, {}} を返す
template<int MAX_WIDTH>
std::pair<int, std::vector<int>> linear_equation_F2(BitMatrix<MAX_WIDTH> A, std::vector<int> b) {
int H = A.H, W = A.W;
int rank = A.row_reduction(b);
// 解の存在チェック
for(int i = rank; i < H; i++) if(b[i]) {
return {-1, {}};
}
std::vector<int> ret(W);
for(int i = 0; i < rank; i++) {
int p = -1;
for(int j = 0; j < W; j++) {
if(A[i][j]) {
p = j;
break;
}
}
if(p == -1) continue;
ret[p] = b[i];
}
return {rank, ret};
}
#line 350 "main.cpp"
using Query = tuple<int, int, int, int, int>;
const int MAX_H = 2048;
const int MAX_W = MAX_H * 4;
/*
sum[i][j] = [0, i) × [0, j) の和
sum[b][d] - sum[a][d] - sum[b][c] + sum[a][c] = (e == 2 ? 1 : 0)
*/
int main() {
map<pair<int, int>, int> ID;
vector<pair<int, int>> rev;
auto f = [&](int i, int j) -> int {
if(ID.count({i, j})) return ID[{i, j}];
int ret = SZ(ID);
ID[{i, j}] = ret;
rev.emplace_back(i, j);
return ret;
};
INT(N, Q);
vector<Query> qs(Q);
int eq_num = 0;
for(auto& [a, b, c, d, e] : qs) {
cin >> a >> b >> c >> d >> e;
a--;
c--;
if(e == 0) continue;
f(a, c);
f(a, d);
f(b, c);
f(b, d);
eq_num++;
}
debug(eq_num);
int sz = SZ(ID);
BitMatrix<MAX_W> mat(eq_num, sz);
vector<int> res(eq_num, 0);
{
int i = 0;
for(auto& [a, b, c, d, e] : qs) {
if(e == 0) continue;
for(int ii : {a, b}) {
for(int jj : {c, d}) {
mat[i][f(ii, jj)] = 1;
}
}
res[i] = (e == 2 ? 1 : 0);
i++;
}
}
auto [rank, answer] = linear_equation_F2<MAX_W>(mat, res);
if(rank == -1) {
print("No");
return 0;
}
auto out = make_vector<int>({N, N}, 0);
{
auto tmp = make_vector<int>({N + 1, N + 1}, 0);
REP(i, sz) {
auto [ii, jj] = rev[i];
tmp[ii][jj] = answer[i];
}
REP(i, N) REP(j, N) {
out[i][j] = (tmp[i + 1][j + 1] ^ tmp[i][j + 1] ^ tmp[i + 1][j] ^ tmp[i][j]) + 1;
}
}
{
imos2D<int> imos(N, N);
for(const auto& [a, b, c, d, e] : qs) {
if(e == 0) continue;
imos.add(a, c, b, d, 1);
}
imos.build();
sum2D<int> sum(N, N);
REP(i, N) REP(j, N) {
if(imos[i][j] == 0) {
out[i][j] = 0;
sum.add(i, j, 1);
}
}
sum.build();
for(auto& [a, b, c, d, e] : qs) {
if(e == 0 and sum.get_sum(a, b, c, d) == 0) {
print("No");
return 0;
}
}
}
print("Yes");
REP(i, N) print(out[i]);
}
Submission Info
| Submission Time |
|
| Task |
Ex - Construct a Matrix |
| User |
siro53 |
| Language |
C++ 23 (gcc 12.2) |
| Score |
600 |
| Code Size |
18103 Byte |
| Status |
AC |
| Exec Time |
347 ms |
| Memory |
52960 KiB |
Compile Error
main.cpp:1: warning: ignoring ‘#pragma region Macros’ [-Wunknown-pragmas]
main.cpp:345: warning: ignoring ‘#pragma endregion Macros’ [-Wunknown-pragmas]
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_one_00.txt, 01_one_01.txt, 01_one_02.txt, 01_one_03.txt, 01_one_04.txt, 01_one_05.txt, 01_one_06.txt, 01_one_07.txt, 01_one_08.txt, 02_small_00.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 03_smallzero_00.txt, 03_smallzero_01.txt, 03_smallzero_02.txt, 03_smallzero_03.txt, 03_smallzero_04.txt, 04_rnd_00.txt, 04_rnd_01.txt, 04_rnd_02.txt, 04_rnd_03.txt, 04_rnd_04.txt, 05_rndzero_00.txt, 05_rndzero_01.txt, 05_rndzero_02.txt, 05_rndzero_03.txt, 05_rndzero_04.txt, 06_superrnd_00.txt, 06_superrnd_01.txt, 06_superrnd_02.txt, 06_superrnd_03.txt, 06_superrnd_04.txt, 07_lastchange_00.txt, 07_lastchange_01.txt, 07_lastchange_02.txt, 07_lastchange_03.txt, 07_lastchange_04.txt, 08_wide_00.txt, 08_wide_01.txt, 08_wide_02.txt, 08_wide_03.txt, 08_wide_04.txt, 09_hand_00.txt, 09_hand_01.txt, 09_hand_02.txt, 09_hand_03.txt, 09_hand_04.txt, 09_hand_05.txt, 09_hand_06.txt, 10_worst_00.txt, 10_worst_01.txt, 10_worst_02.txt, 10_worst_03.txt, 10_worst_04.txt, 10_worst_05.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3416 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3472 KiB |
| 01_one_00.txt |
AC |
1 ms |
3500 KiB |
| 01_one_01.txt |
AC |
1 ms |
3480 KiB |
| 01_one_02.txt |
AC |
1 ms |
3520 KiB |
| 01_one_03.txt |
AC |
1 ms |
3524 KiB |
| 01_one_04.txt |
AC |
1 ms |
3508 KiB |
| 01_one_05.txt |
AC |
1 ms |
3420 KiB |
| 01_one_06.txt |
AC |
1 ms |
3652 KiB |
| 01_one_07.txt |
AC |
1 ms |
3456 KiB |
| 01_one_08.txt |
AC |
1 ms |
3420 KiB |
| 02_small_00.txt |
AC |
3 ms |
7016 KiB |
| 02_small_01.txt |
AC |
3 ms |
6964 KiB |
| 02_small_02.txt |
AC |
4 ms |
7020 KiB |
| 02_small_03.txt |
AC |
4 ms |
7308 KiB |
| 02_small_04.txt |
AC |
4 ms |
7008 KiB |
| 03_smallzero_00.txt |
AC |
1 ms |
3412 KiB |
| 03_smallzero_01.txt |
AC |
1 ms |
3572 KiB |
| 03_smallzero_02.txt |
AC |
1 ms |
3508 KiB |
| 03_smallzero_03.txt |
AC |
2 ms |
4148 KiB |
| 03_smallzero_04.txt |
AC |
2 ms |
3920 KiB |
| 04_rnd_00.txt |
AC |
213 ms |
52856 KiB |
| 04_rnd_01.txt |
AC |
210 ms |
52960 KiB |
| 04_rnd_02.txt |
AC |
210 ms |
52856 KiB |
| 04_rnd_03.txt |
AC |
214 ms |
52656 KiB |
| 04_rnd_04.txt |
AC |
216 ms |
52556 KiB |
| 05_rndzero_00.txt |
AC |
195 ms |
52360 KiB |
| 05_rndzero_01.txt |
AC |
181 ms |
51288 KiB |
| 05_rndzero_02.txt |
AC |
179 ms |
50512 KiB |
| 05_rndzero_03.txt |
AC |
182 ms |
50192 KiB |
| 05_rndzero_04.txt |
AC |
181 ms |
50256 KiB |
| 06_superrnd_00.txt |
AC |
57 ms |
51996 KiB |
| 06_superrnd_01.txt |
AC |
59 ms |
52012 KiB |
| 06_superrnd_02.txt |
AC |
58 ms |
51896 KiB |
| 06_superrnd_03.txt |
AC |
62 ms |
51676 KiB |
| 06_superrnd_04.txt |
AC |
62 ms |
51684 KiB |
| 07_lastchange_00.txt |
AC |
83 ms |
52936 KiB |
| 07_lastchange_01.txt |
AC |
211 ms |
52884 KiB |
| 07_lastchange_02.txt |
AC |
212 ms |
52812 KiB |
| 07_lastchange_03.txt |
AC |
84 ms |
52652 KiB |
| 07_lastchange_04.txt |
AC |
83 ms |
52508 KiB |
| 08_wide_00.txt |
AC |
221 ms |
52504 KiB |
| 08_wide_01.txt |
AC |
222 ms |
52428 KiB |
| 08_wide_02.txt |
AC |
223 ms |
52332 KiB |
| 08_wide_03.txt |
AC |
224 ms |
52048 KiB |
| 08_wide_04.txt |
AC |
220 ms |
52108 KiB |
| 09_hand_00.txt |
AC |
232 ms |
52720 KiB |
| 09_hand_01.txt |
AC |
224 ms |
52608 KiB |
| 09_hand_02.txt |
AC |
49 ms |
7484 KiB |
| 09_hand_03.txt |
AC |
228 ms |
52596 KiB |
| 09_hand_04.txt |
AC |
225 ms |
52596 KiB |
| 09_hand_05.txt |
AC |
224 ms |
52572 KiB |
| 09_hand_06.txt |
AC |
221 ms |
52624 KiB |
| 10_worst_00.txt |
AC |
347 ms |
52700 KiB |
| 10_worst_01.txt |
AC |
344 ms |
52712 KiB |
| 10_worst_02.txt |
AC |
212 ms |
52896 KiB |
| 10_worst_03.txt |
AC |
210 ms |
52912 KiB |
| 10_worst_04.txt |
AC |
212 ms |
52900 KiB |
| 10_worst_05.txt |
AC |
210 ms |
52888 KiB |