結果
| 問題 |
No.1711 Divide LCM
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2021-10-03 18:56:49 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 565 ms / 4,000 ms |
| コード長 | 2,709 bytes |
| コンパイル時間 | 1,413 ms |
| コンパイル使用メモリ | 144,124 KB |
| 実行使用メモリ | 54,052 KB |
| 最終ジャッジ日時 | 2024-09-17 17:10:31 |
| 合計ジャッジ時間 | 8,867 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#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);
}
}
hitonanode