結果

問題 No.2112 All 2x2 are Equal
コンテスト
ユーザー chro_96
提出日時 2022-10-28 22:23:24
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,001 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 171 ms
コンパイル使用メモリ 40,036 KB
最終ジャッジ日時 2026-02-22 09:40:55
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main () {
  int h = 0;
  int w = 0;
  
  int res = 0;
  
  int t = 0;
  int ans[1000][1000] = {};
  
  res = scanf("%d", &h);
  res = scanf("%d", &w);
  
  if (h%2 == 1 && w%2 == 0) {
    int tmp = h;
    h = w;
    w = tmp;
    t = 1;
  }
  
  for (int i = 0; i < h/2; i++) {
    for (int j = 0; j < w; j++) {
      ans[i*2+j%2][j] = i*w+j+1;
      ans[i*2+1-j%2][j] = h*w-i*w-j;
    }
  }
  
  if (h%2 == 1) {
    for (int j = 0; j < w; j += 2) {
      ans[h-1][j] = w*(h/2)+j+1;
    }
    for (int j = 1; j < w; j += 2) {
      ans[h-1][j] = h*w-w*(h/2)-j;
    }
  }
  
  printf("Yes\n");
  if (t > 0) {
    for (int i = 0; i < w; i++) {
      printf("%d", ans[0][i]);
      for (int j = 1; j < h; j++) {
        printf(" %d", ans[j][i]);
      }
      printf("\n");
    }
  } else {
    for (int i = 0; i < h; i++) {
      printf("%d", ans[i][0]);
      for (int j = 1; j < w; j++) {
        printf(" %d", ans[i][j]);
      }
      printf("\n");
    }
  }
  
  return 0;
}
0