結果

問題 No.2212 One XOR Matrix
ユーザー SSRSSSRS
提出日時 2023-02-10 21:39:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,288 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 171,320 KB
実行使用メモリ 9,320 KB
最終ジャッジ日時 2023-09-21 22:43:46
合計ジャッジ時間 4,002 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 22 ms
4,660 KB
testcase_09 AC 85 ms
9,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

 #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> solve0(int N){
  vector<vector<int>> ans(1 << N, vector<int>(1 << N));
  for (int i = 0; i < (1 << N); i++){
    for (int j = 0; j < (1 << N); j++){
      ans[i][j] = (i << N) | j;
    }
  }
  return ans;
}
vector<vector<int>> solve1(int N){
  if (N == 2){
    return {{7, 14, 0, 8}, {4, 12, 2, 11}, {15, 9, 6, 1}, {13, 10, 5, 3}};
  } else {
    vector<vector<int>> A = solve0(N - 1);
    vector<vector<int>> B = solve1(N - 1);
    vector<vector<int>> ans(1 << N, vector<int>(1 << N));
    for (int i = 0; i < (1 << (N - 1)); i++){
      for (int j = 0; j < (1 << (N - 1)); j++){
        ans[i][j] = B[i][j];
        ans[i][(1 << (N - 1)) + j] = A[i][j] + (1 << (N * 2 - 2));
        ans[(1 << (N - 1)) + i][j] = A[i][j] + (1 << (N * 2 - 1));
        ans[(1 << (N - 1)) + i][(1 << (N - 1)) + j] = B[i][j] + (1 << (N * 2 - 2)) + (1 << (N * 2 - 1));
      }
    }
    return ans;
  }
}
int main(){
  int N;
  cin >> N;
  if (N == 1){
    cout << -1 << endl;
  } else {
    vector<vector<int>> ans = solve1(N);
    for (int i = 0; i < (1 << N); i++){
      for (int j = 0; j < (1 << N); j++){
        cout << ans[i][j];
        if (j < (1 << N) - 1){
          cout << ' ';
        }
      }
      cout << endl;
    }
  }
}
0