結果
| 問題 |
No.2212 One XOR Matrix
|
| コンテスト | |
| ユーザー |
maeshun
|
| 提出日時 | 2024-07-07 18:00:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 111 ms / 2,000 ms |
| コード長 | 2,034 bytes |
| コンパイル時間 | 4,404 ms |
| コンパイル使用メモリ | 254,268 KB |
| 最終ジャッジ日時 | 2025-02-22 02:33:30 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
# include <debug_print.hpp>
# define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
# define dbg(...) (static_cast<void>(0))
#endif
int main()
{
int n;
cin >> n;
if(n==1) {
cout << -1 << endl;
return 0;
}
vector<vector<int>> a = {{7, 14, 0, 8}
,{4, 12, 2, 11}
,{15, 9, 6, 1}
,{13, 10, 5, 3}};
auto f = [&](auto f, int cnt) -> vector<vector<int>> {
if(cnt==2) return a;
auto b = f(f, cnt-1);
int r = 1<<(cnt*2-1);
int l = 1<<(cnt*2-2);
vector<vector<int>> A(1<<cnt-1, vector<int>(1<<cnt-1));
rep(i,1<<cnt-1)rep(j,1<<cnt-1) A[i][j] = i*(1<<cnt-1)+j;
rep(i,1<<cnt-1){
if(i%2==1) reverse(A.begin(),A.end());
}
vector<vector<int>> ret(1<<cnt, vector<int>(1<<cnt));
rep(i,2)rep(j,2) {
int add = 0;
if(i>>0&1) add += r;
if(j>>0&1) add += l;
for(int k=0;k<1<<(cnt-1);k++)for(int t=0;t<1<<(cnt-1);t++) {
if(i^j) {
ret[i*(1<<cnt-1)+k][j*(1<<cnt-1)+t] = A[k][t] + add;
}
else{
ret[i*(1<<cnt-1)+k][j*(1<<cnt-1)+t] = b[k][t] + add;
}
}
}
return ret;
};
auto ans = f(f, n);
rep(i,1<<n){
rep(j,1<<n) {
cout << ans[i][j] << " ";
}
cout << endl;
}
rep(i,1<<n) {
int x = 0;
rep(j,1<<n) x^=ans[i][j];
assert(x==1);
}
rep(i,1<<n) {
int x = 0;
rep(j,1<<n) x^=ans[j][i];
assert(x==1);
}
return 0;
}
maeshun