結果

問題 No.1711 Divide LCM
ユーザー tamatotamato
提出日時 2021-10-16 11:15:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,465 ms / 4,000 ms
コード長 1,978 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 81,940 KB
実行使用メモリ 200,124 KB
最終ジャッジ日時 2023-10-17 22:06:35
合計ジャッジ時間 17,564 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
56,084 KB
testcase_01 AC 43 ms
56,084 KB
testcase_02 AC 43 ms
56,020 KB
testcase_03 AC 71 ms
71,260 KB
testcase_04 AC 110 ms
78,332 KB
testcase_05 AC 159 ms
80,924 KB
testcase_06 AC 118 ms
78,392 KB
testcase_07 AC 143 ms
80,288 KB
testcase_08 AC 112 ms
79,032 KB
testcase_09 AC 198 ms
84,720 KB
testcase_10 AC 123 ms
78,540 KB
testcase_11 AC 256 ms
86,888 KB
testcase_12 AC 122 ms
78,436 KB
testcase_13 AC 58 ms
66,828 KB
testcase_14 AC 94 ms
77,624 KB
testcase_15 AC 101 ms
77,880 KB
testcase_16 AC 59 ms
66,816 KB
testcase_17 AC 94 ms
77,500 KB
testcase_18 AC 301 ms
122,072 KB
testcase_19 AC 306 ms
124,444 KB
testcase_20 AC 308 ms
124,328 KB
testcase_21 AC 380 ms
159,044 KB
testcase_22 AC 1,465 ms
176,440 KB
testcase_23 AC 782 ms
200,124 KB
testcase_24 AC 346 ms
118,280 KB
testcase_25 AC 358 ms
119,368 KB
testcase_26 AC 324 ms
117,880 KB
testcase_27 AC 341 ms
123,656 KB
testcase_28 AC 322 ms
119,636 KB
testcase_29 AC 83 ms
77,084 KB
testcase_30 AC 351 ms
128,844 KB
testcase_31 AC 78 ms
75,020 KB
testcase_32 AC 395 ms
155,384 KB
testcase_33 AC 381 ms
155,736 KB
testcase_34 AC 106 ms
78,312 KB
testcase_35 AC 348 ms
114,296 KB
testcase_36 AC 405 ms
116,736 KB
testcase_37 AC 366 ms
115,432 KB
testcase_38 AC 404 ms
163,212 KB
testcase_39 AC 400 ms
158,532 KB
testcase_40 AC 71 ms
73,376 KB
testcase_41 AC 69 ms
71,324 KB
testcase_42 AC 69 ms
73,372 KB
testcase_43 AC 66 ms
71,308 KB
testcase_44 AC 67 ms
73,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


def main():
    import sys
    from itertools import combinations
    import random
    input = sys.stdin.readline

    N = int(input())
    A = []
    PE = []
    P = {}
    for i in range(N):
        M = int(input())
        a = 1
        D = {}
        for j in range(M):
            p, e = map(int, input().split())
            if p not in P:
                P[p] = 0
            P[p] = max(P[p], e)
            a *= p ** e
            D[p] = e
        A.append(a)
        PE.append(D)

    B = []
    BA = []
    BB = []
    for i in range(N):
        D = PE[i]
        b = set()
        for p in D:
            if D[p] == P[p]:
                b.add(p)
        if len(b) > 0:
            B.append(b)
            BA.append(A[i])
        else:
            BB.append(A[i])

    for i, b in enumerate(B):
        ok = 0
        for pp in P:
            if pp not in b:
                # ans[j].append(BA[i])
                ok = 1
                break
        if not ok:
            print(-1)
            exit()

    L = len(P)
    P_list = list(P.keys())

    D_set = set()
    for b in B:
        lb = len(b)
        bb = list(b)
        for i in range(1 << lb):
            d = 1
            for j in range(lb):
                if i >> j & 1:
                    d *= bb[j]
            D_set.add(d)

    for k in range(2, L+1):
        for J in combinations(P_list, k):
            J = list(J)
            q = 1
            for pp in J:
                q *= pp
            if q in D_set:
                continue
            ans = [[] for _ in range(k)]
            for i, b in enumerate(B):
                for j, pp in enumerate(J):
                    if pp not in b:
                        ans[j].append(BA[i])
                        break
            ans[0].extend(BB)
            print(k)
            for a in ans:
                a = [len(a)] + a
                print(*a)
            exit()


if __name__ == '__main__':
    main()
0