結果
| 問題 | No.2112 All 2x2 are Equal | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2022-11-01 20:13:44 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 102 ms / 2,000 ms | 
| コード長 | 1,110 bytes | 
| コンパイル時間 | 408 ms | 
| コンパイル使用メモリ | 43,460 KB | 
| 実行使用メモリ | 7,044 KB | 
| 最終ジャッジ日時 | 2024-07-16 09:51:11 | 
| 合計ジャッジ時間 | 5,530 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 34 | 
ソースコード
/* -*- 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;
}
            
            
            
        