結果

問題 No.1711 Divide LCM
ユーザー 👑 emthrmemthrm
提出日時 2021-11-03 16:47:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,725 bytes
コンパイル時間 2,774 ms
コンパイル使用メモリ 217,944 KB
実行使用メモリ 39,196 KB
最終ジャッジ日時 2024-04-21 08:10:36
合計ジャッジ時間 11,250 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 10 ms
6,944 KB
testcase_05 AC 49 ms
6,940 KB
testcase_06 AC 15 ms
6,940 KB
testcase_07 AC 36 ms
6,940 KB
testcase_08 AC 13 ms
6,944 KB
testcase_09 AC 93 ms
6,940 KB
testcase_10 AC 20 ms
6,940 KB
testcase_11 AC 144 ms
6,940 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 7 ms
6,944 KB
testcase_15 AC 9 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 7 ms
6,940 KB
testcase_18 TLE -
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 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY[]{1, 0, -1, 0}, DX[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}, DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int pow(int n, int ex) {
  int tmp = n, res = 1;
  for (; ex > 0; ex >>= 1) {
    if (ex & 1) res *= tmp;
    tmp *= tmp;
  }
  return res;
}

int main() {
  int n; cin >> n;
  vector<vector<int>> p(n), e(n);
  map<int, int> max_e;
  REP(i, n) {
    int m; cin >> m;
    p[i].resize(m);
    e[i].resize(m);
    REP(j, m) {
      cin >> p[i][j] >> e[i][j];
      chmax(max_e[p[i][j]], e[i][j]);
    }
  }
  // for (auto [pi, ei] : max_e) cerr << pi << ' ' << ei << '\n';
  REP(i, n) {
    if (p[i].size() < max_e.size()) continue;
    bool is_lcm = true;
    REP(j, p[i].size()) is_lcm &= max_e[p[i][j]] == e[i][j];
    if (is_lcm) {
      cout << "-1\n";
      return 0;
    }
  }
  set<ll> d;
  REP(i, n) REP(j, 1 << p[i].size()) {
    int mul = 1;
    REP(k, p[i].size()) {
      if (j >> k & 1) mul *= pow(p[i][k], e[i][k]);
    }
    d.emplace(mul);
  }
  // for (ll e : d) cerr << e << ' ';
  // cerr << '\n';
  vector<int> s;
  vector<pair<int, int>> max_e_v;
  for (auto [pi, ei] : max_e) {
    s.emplace_back(pow(pi, ei));
    max_e_v.emplace_back(pi, ei);
  }
  vector<int> tmp;
  auto f = [&](auto&& f, int i, ll mul) -> void {
    if (tmp.size() >= s.size()) return;
    if (d.count(mul) == 0) {
      s = tmp;
      return;
    }
    if (i == max_e_v.size()) return;
    f(f, i + 1, mul);
    int pw = pow(max_e_v[i].first, max_e_v[i].second);
    tmp.emplace_back(pw);
    f(f, i + 1, mul * pw);
    tmp.pop_back();
  };
  f(f, 0, 1);
  const int k = s.size();
  vector<vector<int>> ans(k);
  REP(i, n) {
    int a = 1;
    REP(j, p[i].size()) a *= pow(p[i][j], e[i][j]);
    REP(j, k) {
      if (a % s[j] > 0) {
        ans[j].emplace_back(a);
        break;
      }
    }
  }
  cout << k << '\n';
  REP(i, k) {
    cout << ans[i].size();
    for (int ans_j : ans[i]) cout << ' ' << ans_j;
    cout << '\n';
  }
  return 0;
}
0