結果

問題 No.1711 Divide LCM
ユーザー tamatotamato
提出日時 2021-10-15 23:45:00
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,358 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 82,072 KB
実行使用メモリ 181,868 KB
最終ジャッジ日時 2023-10-17 21:36:35
合計ジャッジ時間 19,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 43 ms
56,164 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 AC 71 ms
73,488 KB
testcase_41 AC 66 ms
71,432 KB
testcase_42 AC 68 ms
73,480 KB
testcase_43 AC 66 ms
73,472 KB
testcase_44 AC 66 ms
73,472 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 = []
    B_val = []
    for i in range(N):
        D = PE[i]
        b = set()
        val = 1
        for p in D:
            if D[p] == P[p]:
                b.add(p)
                val *= p
        if len(b) > 0:
            B.append(b)
            BA.append(A[i])
            B_val.append(val)
        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())

    cov = [0] * (L+1)
    seen = set()
    for b, val in zip(B, B_val):
        if val not in seen:
            seen.add(val)
            cov[len(b)] += 1

    B_val = list(set(B_val))
    comb = L
    P_list = random.shuffle(P_list)
    for k in range(2, L+1):
        comb *= (L - k + 1)
        comb //= k
        if cov[k] == comb:
            continue
        for J in combinations(P_list, k):
            J = list(J)
            q = 1
            for pp in J:
                q *= pp
            if q in B_val:
                continue
            ans = [[] for _ in range(k)]
            flg = 1
            for i, b in enumerate(B_val):
                if b % q == 0:
                    flg = 0
                    break
            if flg:
                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