結果

問題 No.1974 2x2 Flipper
ユーザー tnakao0123tnakao0123
提出日時 2022-06-13 11:24:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,137 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 42,796 KB
実行使用メモリ 7,112 KB
最終ジャッジ日時 2023-10-25 09:48:50
合計ジャッジ時間 5,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 12 ms
5,924 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 66 ms
6,932 KB
testcase_04 AC 30 ms
5,924 KB
testcase_05 AC 19 ms
5,924 KB
testcase_06 AC 46 ms
5,956 KB
testcase_07 AC 31 ms
6,600 KB
testcase_08 AC 8 ms
5,924 KB
testcase_09 AC 48 ms
5,924 KB
testcase_10 AC 7 ms
5,924 KB
testcase_11 AC 38 ms
5,924 KB
testcase_12 AC 65 ms
6,104 KB
testcase_13 AC 40 ms
6,268 KB
testcase_14 AC 25 ms
5,924 KB
testcase_15 AC 75 ms
6,368 KB
testcase_16 AC 8 ms
5,924 KB
testcase_17 AC 54 ms
6,932 KB
testcase_18 AC 7 ms
4,348 KB
testcase_19 AC 9 ms
5,924 KB
testcase_20 AC 30 ms
5,924 KB
testcase_21 AC 97 ms
7,112 KB
testcase_22 AC 97 ms
7,104 KB
testcase_23 AC 97 ms
7,112 KB
testcase_24 AC 97 ms
7,108 KB
testcase_25 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1974.cc:  No.1974 2x2 Flipper - 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 */

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

/* main */

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

  int c = 0;
  if (h > 1 && w > 1 && (h & w & 1)) {
    for (int i = 0; i < h; i++) fill(as[i], as[i] + w, 1);
    c = h * w;

    if (h <= w) {
      for (int y = 0, x = 0, d = 1; x < w;) {
	for (int i = 0; i < d; i++) as[y][x++] = 0, c--;
	if (++y >= h) y = 0, d = 2;
      }
    }
    else {
      for (int x = 0, y = 0, d = 1; y < h;) {
	for (int i = 0; i < d; i++) as[y++][x] = 0, c--;
	if (++x >= w) x = 0, d = 2;
      }
    }
  }
  else {
    int he = h & ~1, we = w & ~1;
    for (int i = 0; i < he; i++)
      for (int j = 0; j < we; j++) as[i][j] = 1, c++;
  }

  printans(h, w, c);
  return 0;
}
0