結果

問題 No.1711 Divide LCM
ユーザー tamatotamato
提出日時 2021-10-16 11:10:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,347 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 81,956 KB
実行使用メモリ 167,880 KB
最終ジャッジ日時 2023-10-17 22:05:32
合計ジャッジ時間 23,435 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
56,264 KB
testcase_01 AC 43 ms
56,264 KB
testcase_02 AC 41 ms
56,200 KB
testcase_03 AC 74 ms
73,516 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 327 ms
122,052 KB
testcase_19 AC 326 ms
124,012 KB
testcase_20 AC 333 ms
124,104 KB
testcase_21 AC 375 ms
164,288 KB
testcase_22 AC 3,473 ms
115,872 KB
testcase_23 AC 1,272 ms
113,908 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 372 ms
131,384 KB
testcase_28 WA -
testcase_29 AC 86 ms
77,236 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 372 ms
160,568 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 402 ms
167,880 KB
testcase_39 AC 393 ms
162,640 KB
testcase_40 AC 70 ms
73,528 KB
testcase_41 AC 65 ms
71,468 KB
testcase_42 AC 66 ms
73,516 KB
testcase_43 AC 65 ms
73,508 KB
testcase_44 AC 66 ms
73,508 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

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

    comb = L
    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 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