結果

問題 No.1711 Divide LCM
ユーザー 👑 emthrmemthrm
提出日時 2021-11-03 17:08:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,450 ms / 4,000 ms
コード長 2,793 bytes
コンパイル時間 2,842 ms
コンパイル使用メモリ 228,112 KB
実行使用メモリ 46,080 KB
最終ジャッジ日時 2024-04-21 08:34:14
合計ジャッジ時間 17,411 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 9 ms
6,940 KB
testcase_05 AC 49 ms
6,940 KB
testcase_06 AC 15 ms
6,944 KB
testcase_07 AC 36 ms
6,940 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 91 ms
6,944 KB
testcase_10 AC 20 ms
6,944 KB
testcase_11 AC 147 ms
6,940 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 6 ms
6,940 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 7 ms
6,944 KB
testcase_18 AC 535 ms
32,640 KB
testcase_19 AC 526 ms
32,512 KB
testcase_20 AC 536 ms
32,640 KB
testcase_21 AC 149 ms
19,676 KB
testcase_22 AC 2,450 ms
32,768 KB
testcase_23 AC 1,760 ms
46,080 KB
testcase_24 AC 195 ms
14,464 KB
testcase_25 AC 188 ms
13,568 KB
testcase_26 AC 177 ms
12,032 KB
testcase_27 AC 165 ms
13,440 KB
testcase_28 AC 159 ms
12,160 KB
testcase_29 AC 5 ms
6,940 KB
testcase_30 AC 193 ms
19,968 KB
testcase_31 AC 4 ms
6,944 KB
testcase_32 AC 180 ms
24,576 KB
testcase_33 AC 181 ms
24,448 KB
testcase_34 AC 18 ms
6,940 KB
testcase_35 AC 289 ms
12,672 KB
testcase_36 AC 324 ms
13,312 KB
testcase_37 AC 329 ms
13,184 KB
testcase_38 AC 195 ms
29,136 KB
testcase_39 AC 190 ms
25,856 KB
testcase_40 AC 3 ms
6,944 KB
testcase_41 AC 3 ms
6,940 KB
testcase_42 AC 3 ms
6,944 KB
testcase_43 AC 3 ms
6,940 KB
testcase_44 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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<pair<int, int>> max_e_v;
  for (auto [pi, ei] : max_e) max_e_v.emplace_back(pi, ei);
  vector<int> s;
  queue<tuple<ll, int, vector<int>>> que({{1, 0, vector<int>{}}});
  while (!que.empty()) {
    auto [mul, i, tmp_] = que.front(); que.pop();
    vector<int> tmp = tmp_;
    FOR(j, i, max_e_v.size()) {
      tmp.emplace_back(pow(max_e_v[j].first, max_e_v[j].second));
      if (d.count(mul * tmp.back()) == 0) {
        s = tmp;
        while (!que.empty()) que.pop();
        break;
      } else {
        que.emplace(mul * tmp.back(), j + 1, tmp);
      }
      tmp.pop_back();
    }
  }
  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