結果

問題 No.1988 Divisor Tiling
ユーザー Drice27149Drice27149
提出日時 2022-06-24 22:28:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 61,020 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 05:37:40
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
/*
6
1, 2, 3,
28
1, 2, 14, 4, 7,
496
1, 2, 248, 4, 124, 8, 62, 16, 31,
8128
1, 2, 4064, 4, 2032, 8, 1016, 16, 508, 32, 254, 64, 127
*/
0