結果
問題 | No.1988 Divisor Tiling |
ユーザー |
![]() |
提出日時 | 2022-06-24 22:28:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,254 bytes |
コンパイル時間 | 825 ms |
コンパイル使用メモリ | 59,440 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 18:23:51 |
合計ジャッジ時間 | 2,293 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 |
ソースコード
#include <cstdio>#include <vector>#include <algorithm>using namespace std;long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }vector<int> factor(int u) {vector<int> res = {1};for (int i = 2; i * 1ll * i <= u; i++) {if (u % i == 0) {res.push_back(i);int j = u / i;if (j != i) res.push_back(j);}}return res;}int main() {int n, m;scanf("%d%d", &n, &m);auto res = factor(n);sort(res.begin(), res.end());vector<int> seq;for (int u: res) {for (int it = 0; it < u; it++) seq.push_back(u);}int x = m, y = n / m;vector<vector<int>> a(x, vector<int> (y));int p = 0;if (x < y) {for (int i = 0; i < m; i++) {for (int j = 0; j < n / m; j++) a[i][j] = seq[p++];}} else {for (int i = 0; i < y; i++) {for (int j = 0; j < x; j++) a[j][i] = seq[p++];}}for (int i = 0; i < x; i++) {for (int j = 0; j < y; j++) printf("%d ", a[i][j]);printf("\n");}return 0;}/*61, 2, 3,281, 2, 14, 4, 7,4961, 2, 248, 4, 124, 8, 62, 16, 31,81281, 2, 4064, 4, 2032, 8, 1016, 16, 508, 32, 254, 64, 127*/