結果

問題 No.1711 Divide LCM
ユーザー 👑 hitonanodehitonanode
提出日時 2021-10-03 18:56:49
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 836 ms / 4,000 ms
コード長 2,709 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 144,184 KB
実行使用メモリ 53,960 KB
最終ジャッジ日時 2023-10-17 19:58:28
合計ジャッジ時間 12,012 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 7 ms
4,348 KB
testcase_05 AC 27 ms
5,932 KB
testcase_06 AC 9 ms
4,388 KB
testcase_07 AC 21 ms
5,576 KB
testcase_08 AC 9 ms
4,680 KB
testcase_09 AC 52 ms
8,036 KB
testcase_10 AC 13 ms
4,448 KB
testcase_11 AC 77 ms
9,268 KB
testcase_12 AC 14 ms
4,452 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 140 ms
22,124 KB
testcase_19 AC 137 ms
22,132 KB
testcase_20 AC 141 ms
22,112 KB
testcase_21 AC 151 ms
28,520 KB
testcase_22 AC 836 ms
38,996 KB
testcase_23 AC 700 ms
53,960 KB
testcase_24 AC 124 ms
21,256 KB
testcase_25 AC 125 ms
21,256 KB
testcase_26 AC 125 ms
21,276 KB
testcase_27 AC 124 ms
21,904 KB
testcase_28 AC 123 ms
21,232 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 181 ms
23,768 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 146 ms
27,020 KB
testcase_33 AC 146 ms
27,176 KB
testcase_34 AC 9 ms
4,432 KB
testcase_35 AC 158 ms
20,796 KB
testcase_36 AC 172 ms
21,052 KB
testcase_37 AC 172 ms
21,064 KB
testcase_38 AC 203 ms
28,148 KB
testcase_39 AC 163 ms
28,444 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;


constexpr long long THRES = 1000000000;

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N, 1);
    vector<map<int, int>> facA(N);

    map<int, int> lcmall;
    vector<int> ps;
    for (int i = 0; i < N; ++i) {
        int m;
        cin >> m;
        while (m--) {
            int p, e;
            cin >> p >> e;
            ps.push_back(p);
            facA[i][p] = e;
            if (lcmall[p] < e) lcmall[p] = e;
            while (e--) A[i] *= p;
        }
    }

    for (const auto &mp : facA) {
        if (mp.size() == lcmall.size() and mp == lcmall) {
            puts("-1");
            return 0;
        }
    }

    sort(ps.begin(), ps.end());
    ps.erase(unique(ps.begin(), ps.end()), ps.end());

    unordered_set<long long> pgs;

    for (int i = 0; i < N; ++i) {
        vector<int> pvs;
        for (auto [p, d] : facA[i]) {
            if (lcmall[p] == d) pvs.push_back(p);
        }
        for (int s = 1; s < 1 << pvs.size(); s++) {
            int v = 1;
            for (int j = 0; j < int(pvs.size()); ++j) {
                if ((s >> j) & 1) {
                    v *= pvs[j];
                    if (v > THRES) break;
                }
            }
            pgs.insert(v);
        }
    }

    auto build = [&](const vector<int> &P) {
        vector<vector<int>> ret(P.size());
        for (int i = 0; i < N; ++i) {
            for (int g = 0; g < int(P.size()); ++g) {
                const int &p = P[g];
                if (facA[i][p] < lcmall[p]) {
                    ret[g].push_back(A[i]);
                    break;
                }
            }
        }
        cout << ret.size() << '\n';
        for (const auto &v : ret) {
            cout << v.size();
            for (auto x : v) cout << ' ' << x;
            cout << '\n';
        }
        exit(0);
    };

    if (ps.size() >= 2 and (long long)(ps.back()) * ps[ps.size() - 2] > *max_element(A.begin(), A.end())) {
        build({ps.back(), ps[ps.size() - 2]});
    }

    for (int num = 2;; ++num) {
        vector<int> ans(num);
        auto rec = [&](auto &&self, int sz, int nl, long long prod) -> void {
            if (sz == num) {
                if (pgs.count(prod)) return;
                build(ans);
            }
            if (prod > THRES) return;
            for (int i = nl; i < int(ps.size()); ++i) {
                ans[sz] = ps[i];
                self(self, sz + 1, i + 1, prod * ps[i]);
            }
        };
        rec(rec, 0, 0, 1);
    }
}
0