結果

問題 No.2212 One XOR Matrix
ユーザー tnakao0123
提出日時 2024-07-05 14:37:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 42,620 KB
最終ジャッジ日時 2025-02-22 02:13:45
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:62:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2212.cc:  No.2212 One XOR Matrix - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 10;
const int NBITS = 1 << MAX_N;
const int M = 4;
const int MMSK = (1 << M) - 1;

const int bs[M][M] = {
  { 7, 14,  0,  8},
  { 4, 12,  2, 11},
  {15,  9,  6,  1},
  {13, 10,  5,  3},
};

/* typedef */

/* global variables */

int as[NBITS][NBITS], cs[M][M];

/* subroutines */

void check(int n) {
  int nbits = 1 << n;
  bool used[NBITS * NBITS];
  fill(used, used + nbits * nbits, false);
  for (int i = 0; i < nbits; i++) {
    int x = 0;
    for (int j = 0; j < nbits; j++)
      x ^= as[i][j], used[as[i][j]] = true;
    printf(" %d", x);
  }
  putchar('\n');
  for (int j = 0; j < nbits; j++) {
    int x = 0;
    for (int i = 0; i < nbits; i++)
      x ^= as[i][j];
    printf(" %d", x);
  }
  putchar('\n');

  bool ok = true;
  for (int i = 0; ok && i < nbits * nbits; i++) ok = used[i];
  if (ok) puts("OK");
  else puts("NG");
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  if (n <= 1) { puts("-1"); return 0; }

  int nbits = 1 << n;
  for (int i = 0, x = 0; i < nbits; i++)
    for (int j = 0; j < nbits; j++, x++) as[i][j] = x;
  //check(n);

  for (int i0 = 0; i0 < nbits; i0 += M) {
    for (int i = 0, x = 0; i < M; i++)
      for (int j = 0; j < M; j++, x++) {
	int i1 = bs[i][j] / M, j1 = bs[i][j] % M;
	cs[i][j] = as[i0 + i1][i0 + j1];
      }
    for (int i = 0, x = 0; i < M; i++)
      for (int j = 0; j < M; j++, x++)
	as[i0 + i][i0 + j] = cs[i][j];
  }
  //check(n);
  
  for (int i = 0, x = 0; i < nbits; i++)
    for (int j = 0; j < nbits; j++, x++)
      printf("%d%c", as[i][j], (j + 1 < nbits) ? ' ' : '\n');
  
  return 0;
}
0