結果

問題 No.1988 Divisor Tiling
ユーザー magstamagsta
提出日時 2022-03-28 20:06:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,950 bytes
コンパイル時間 8,384 ms
コンパイル使用メモリ 295,396 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-25 01:28:43
合計ジャッジ時間 12,418 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<long long> alldiv(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			if (N / i != i) res.push_back(N / i);
		}
	}
	sort(res.begin(), res.end());
	return res;
}

int main() {
	registerValidation();
	long long N, H;
	N = inf.readLong((long long)1, (long long)10000);
	inf.readSpace();
	H = inf.readLong((long long)1, (long long)10000);
	inf.readEoln();
	inf.readEof();

	assert(N % H == 0);

	long long H_ = H;
	while (H_ > 1) {
		if (H_ % 2 == 0) H /= 2;
		else break;
	}

	if (H_ == 1) {
		auto a = alldiv(N);
		sort(a.begin(), a.end());
		reverse(a.begin(), a.end());
		vector<vector<long long>> ans(H, vector<long long>(N / H, 0));
		int count = 0, count_ = 0;
		for (int i = 1; i < a.size(); i++) {
			if (a[i] >= N / H) {
				for (int j = 0; j < a[i] / (N / H); j++) {
					for (int k = 0; k < N / H; k++) {
						ans[count][k] = a[i];
					}
					count++;
				}
			}
			else {
				for (int j = 0; j < a[i]; j++) {
					ans[H - 1][count_] = a[i];
				}
				count_++;
			}
		}
		for (int i = 0; i < H; i++) {
			cout << ans[i][0];
			for (int j = 1; j < (N / H); j++) {
				cout << " " << ans[i][j];
			}
			cout << endl;
		}
	}
	else {
		auto a = alldiv(N);
		sort(a.begin(), a.end());
		reverse(a.begin(), a.end());
		vector<vector<long long>> ans(H, vector<long long>(N / H, 0));
		int count = 0, count_ = 0;
		for (int i = 1; i < a.size(); i++) {
			if (a[i] >= N / H) {
				for (int j = 0; j < a[i] / H; j++) {
					for (int k = 0; k < H; k++) {
						ans[k][count] = a[i];
					}
					count++;
				}
			}
			else {
				for (int j = 0; j < a[i]; j++) {
					ans[count_][(N / H) - 1] = a[i];
				}
				count_++;
			}
		}
		for (int i = 0; i < H; i++) {
			cout << ans[i][0];
			for (int j = 1; j < (N / H); j++) {
				cout << " " << ans[i][j];
			}
			cout << endl;
		}
	}
}
0