結果
| 問題 |
No.2505 matriX cOnstRuction
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-13 17:14:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
J_ERR
(最初)
|
| 実行時間 | - |
| コード長 | 2,669 bytes |
| コンパイル時間 | 862 ms |
| コンパイル使用メモリ | 81,352 KB |
| 最終ジャッジ日時 | 2025-02-10 14:59:02 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 37 TLE * 27 |
ソースコード
#include <array>
#include <cassert>
#include <iostream>
#include <limits>
#include <tuple>
#include <vector>
int floor_pow2(int n) {
int x = 1;
while ((x << 1) <= n) x <<= 1;
return x;
}
void println() {
std::cout << '\n';
}
template <typename Head, typename ...Tails>
void println(Head&& head, Tails &&...tails) {
std::cout << std::forward<Head>(head);
if constexpr (sizeof...(Tails)) {
std::cout << ' ';
}
println(std::forward<Tails>(tails)...);
}
using Weight = long long;
constexpr int L = 30;
constexpr Weight inf = std::numeric_limits<int>::max();
void solve(int n, int m, const std::vector<int>& r, const std::vector<int>& c, const std::vector<std::vector<int>>& a) {
for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
if (a[0][0] ^ a[0][j] ^ a[i][0] ^ a[i][j]) {
println(-1);
return;
}
}
int bit_num = 0;
for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
bit_num = std::max(bit_num, __builtin_ctz(floor_pow2(a[i][j])) + 1);
}
std::pair<Weight, int> min_cost{ inf, 0 };
for (int x = 0; x < 1 << bit_num; ++x) {
Weight cost = 0;
for (int i = 0; i < n; ++i) {
int s = x ^ a[i][0] ^ a[0][0];
if (s == 0) {
continue;
} else {
cost += 1;
}
}
for (int j = 0; j < m; ++j) {
int t = x ^ a[0][j];
if (t == 0) {
continue;
} else {
cost += 1;
}
}
min_cost = std::min(min_cost, std::pair{ cost, x });
}
auto [cost, X] = min_cost;
if (cost >= inf) {
println(-1);
return;
}
println(cost);
std::vector<std::tuple<char, int, int>> ops;
for (int i = 0; i < n; ++i) {
int s = X ^ a[0][0] ^ a[i][0];
if (s == 0) {
continue;
} else {
println('r', i + 1, s);
}
}
for (int j = 0; j < m; ++j) {
int t = X ^ a[0][j];
if (t == 0) {
continue;
} else {
println('c', j + 1, t);
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t-- > 0) {
int n, m;
std::cin >> n >> m;
std::vector<int> r(n), c(m);
for (auto& e : r) std::cin >> e;
for (auto& e : c) std::cin >> e;
std::vector a(n, std::vector<int>(m));
for (auto& row : a) for (auto& e : row) {
std::cin >> e;
}
solve(n, m, r, c, a);
}
return 0;
}