結果

問題 No.2112 All 2x2 are Equal
ユーザー tnakao0123tnakao0123
提出日時 2022-11-01 20:13:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 43,180 KB
実行使用メモリ 6,964 KB
最終ジャッジ日時 2023-09-23 10:20:04
合計ジャッジ時間 6,215 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 44 ms
6,164 KB
testcase_05 AC 53 ms
5,204 KB
testcase_06 AC 93 ms
6,660 KB
testcase_07 AC 30 ms
4,472 KB
testcase_08 AC 77 ms
6,936 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 36 ms
5,112 KB
testcase_11 AC 24 ms
4,380 KB
testcase_12 AC 29 ms
5,320 KB
testcase_13 AC 83 ms
6,460 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 63 ms
6,684 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 74 ms
6,256 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 6 ms
5,020 KB
testcase_21 AC 72 ms
6,424 KB
testcase_22 AC 5 ms
4,436 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 11 ms
5,184 KB
testcase_25 AC 13 ms
4,500 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 19 ms
4,740 KB
testcase_28 AC 47 ms
6,148 KB
testcase_29 AC 9 ms
6,436 KB
testcase_30 AC 30 ms
4,376 KB
testcase_31 AC 57 ms
6,728 KB
testcase_32 AC 99 ms
6,888 KB
testcase_33 AC 99 ms
6,964 KB
testcase_34 AC 101 ms
6,940 KB
testcase_35 AC 101 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2112.cc:  No.2112 All 2x2 are Equal - yukicoder
 */

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

/* constant */

const int MAX_H = 1000;
const int MAX_W = 1000;

/* typedef */

/* global variables */

int as[MAX_H][MAX_W];

/* subroutines */

/* main */

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

  bool r = false;
  if ((h & 1) && ! (w & 1)) r = true, swap(h, w);

  int x = 1, y = h * w;
  for (int i = 0; i + 1 < h; i += 2)
    for (int j = 0; j < w; j++) {
      int p = j & 1;
      as[i + p][j] = x++, as[i + (p ^ 1)][j] = y--;
    }

  if (h & 1) {
    int s = as[0][0] + as[0][1] + as[1][0] + as[1][1];
    as[h - 1][0] = x++;
    for (int j = 1; j < w; j++)
      as[h - 1][j] = s - (as[h - 2][j - 1] + as[h - 2][j] + as[h - 1][j - 1]);
  }

  if (r) {
    int l = max(h, w);
    for (int i = 0; i < l; i++)
      for (int j = i + 1; j < l; j++)
	swap(as[i][j], as[j][i]);
    swap(h, w);
  }

  puts("Yes");
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      printf("%d%c", as[i][j], (j + 1 < w) ? ' ' : '\n');

  return 0;
}
0