結果

問題 No.1711 Divide LCM
ユーザー 👑 emthrmemthrm
提出日時 2021-11-03 16:59:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,778 bytes
コンパイル時間 3,252 ms
コンパイル使用メモリ 229,004 KB
実行使用メモリ 46,080 KB
最終ジャッジ日時 2024-04-21 08:26:06
合計ジャッジ時間 19,735 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 9 ms
6,940 KB
testcase_05 AC 49 ms
6,944 KB
testcase_06 AC 14 ms
6,944 KB
testcase_07 AC 37 ms
6,944 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 90 ms
6,940 KB
testcase_10 AC 19 ms
6,944 KB
testcase_11 AC 146 ms
6,940 KB
testcase_12 AC 20 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 6 ms
6,944 KB
testcase_15 AC 9 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 543 ms
32,640 KB
testcase_19 AC 555 ms
32,384 KB
testcase_20 AC 575 ms
32,640 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 200 ms
14,464 KB
testcase_25 WA -
testcase_26 AC 186 ms
11,648 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 198 ms
20,096 KB
testcase_31 AC 5 ms
6,944 KB
testcase_32 AC 184 ms
24,704 KB
testcase_33 AC 188 ms
24,512 KB
testcase_34 AC 18 ms
6,940 KB
testcase_35 AC 296 ms
12,800 KB
testcase_36 AC 332 ms
13,312 KB
testcase_37 AC 337 ms
13,312 KB
testcase_38 AC 207 ms
29,128 KB
testcase_39 WA -
testcase_40 AC 3 ms
6,940 KB
testcase_41 AC 3 ms
6,940 KB
testcase_42 AC 3 ms
6,944 KB
testcase_43 AC 3 ms
6,944 KB
testcase_44 AC 3 ms
6,944 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();
      } 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