結果

問題 No.1974 2x2 Flipper
ユーザー magstamagsta
提出日時 2022-03-23 21:51:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,680 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 169,068 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 05:54:41
合計ジャッジ時間 5,581 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 12 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 64 ms
4,348 KB
testcase_04 AC 30 ms
4,348 KB
testcase_05 AC 18 ms
4,348 KB
testcase_06 AC 45 ms
4,348 KB
testcase_07 AC 31 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 48 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 37 ms
4,348 KB
testcase_12 AC 64 ms
4,348 KB
testcase_13 AC 39 ms
4,348 KB
testcase_14 AC 24 ms
4,348 KB
testcase_15 AC 73 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 53 ms
4,348 KB
testcase_18 AC 7 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 29 ms
4,348 KB
testcase_21 AC 95 ms
4,348 KB
testcase_22 AC 96 ms
4,348 KB
testcase_23 AC 95 ms
4,348 KB
testcase_24 AC 96 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int H, W; cin >> H >> W;
	if (H % 2 == 0 && W % 2 == 0) {
		cout << H * W << endl;
		for (int i = 0; i < H; i++) {
			cout << 1;
			for (int j = 1; j < W; j++) {
				cout << " " << 1;
			}
			cout << endl;
		}
	}
	if (H % 2 == 1 && W % 2 == 0) {
		cout << (H - 1) * W << endl;
		for (int i = 0; i < H - 1; i++) {
			cout << 1;
			for (int j = 1; j < W; j++) {
				cout << " " << 1;
			}
			cout << endl;
		}
		cout << 0;
		for (int j = 1; j < W; j++) {
			cout << " " << 0;
		}
		cout << endl;
	}
	if (H % 2 == 0 && W % 2 == 1) {
		cout << H * (W - 1) << endl;
		for (int i = 0; i < H; i++) {
			cout << 1;
			for (int j = 1; j < W - 1; j++) {
				cout << " " << 1;
			}
			cout << " " << 0;
			cout << endl;
		}
	}
	if (H % 2 == 1 && W % 2 == 1) {
		if (H >= W) {
			cout << H * (W - 1) << endl;
			for (int i = 0; i < W; i++) {
				if (i != 0) cout << 1;
				else cout << 0;
				for (int j = 1; j < W; j++) {
					if (i != j) cout << " " << 1;
					else cout << " " << 0;
				}
				cout << endl;
			}
			for (int i = W; i < H; i++) {
				if (((i - W) / 2) % W != 0) cout << 1;
				else cout << 0;
				for (int j = 1; j < W; j++) {
					if (((i - W) / 2) % W != j) cout << " " << 1;
					else cout << " " << 0;
				}
				cout << endl;
			}
		}
		else {
			cout << (H - 1) * W << endl;
			for (int i = 0; i < H; i++) {
				if (i != 0) cout << 1;
				else cout << 0;
				for (int j = 1; j < H; j++) {
					if (i != j) cout << " " << 1;
					else cout << " " << 0;
				}
				for (int j = H; j < W; j++) {
					if (((j - H) / 2) % H != i) cout << " " << 1;
					else cout << " " << 0;
				}
				cout << endl;
			}
		}
	}
}
0