結果
問題 | No.1711 Divide LCM |
ユーザー | LyricalMaestro |
提出日時 | 2024-12-15 03:04:21 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,247 bytes |
コンパイル時間 | 540 ms |
コンパイル使用メモリ | 82,220 KB |
実行使用メモリ | 138,348 KB |
最終ジャッジ日時 | 2024-12-15 03:04:42 |
合計ジャッジ時間 | 20,465 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,764 KB |
testcase_01 | AC | 37 ms
52,620 KB |
testcase_02 | AC | 40 ms
53,088 KB |
testcase_03 | WA | - |
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 | 336 ms
106,984 KB |
testcase_19 | AC | 347 ms
107,796 KB |
testcase_20 | AC | 331 ms
107,460 KB |
testcase_21 | AC | 392 ms
125,092 KB |
testcase_22 | AC | 301 ms
92,164 KB |
testcase_23 | AC | 271 ms
93,804 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 542 ms
127,620 KB |
testcase_33 | AC | 381 ms
125,152 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 380 ms
138,348 KB |
testcase_39 | AC | 400 ms
124,552 KB |
testcase_40 | AC | 108 ms
76,940 KB |
testcase_41 | AC | 93 ms
77,072 KB |
testcase_42 | AC | 96 ms
76,852 KB |
testcase_43 | AC | 95 ms
76,812 KB |
testcase_44 | AC | 96 ms
76,772 KB |
ソースコード
## https://yukicoder.me/problems/no/1711 def calc_s(primes, i): ans = 1 for p, e in primes[i].items(): ans *= pow(p, e) return str(ans) def main(): N = int(input()) primes = [] for _ in range(N): m = int(input()) p_map = {} for _ in range(m): p, e = map(int ,input().split()) p_map[p] = e primes.append(p_map) # LCM(S)を計算 all_primes = {} for i, p_map in enumerate(primes): for p, e in p_map.items(): if p not in all_primes: all_primes[p] = [-1, []] if all_primes[p][0] < e: all_primes[p][0] = e all_primes[p][1].clear() all_primes[p][1].append(i) elif all_primes[p][0] == e: all_primes[p][1].append(i) # LCM(Si) = LCM(S)となるiが存在するか? for p_map in primes: if len(p_map) < len(all_primes): continue not_is_max = False for p, e in p_map.items(): if e < all_primes[p][0]: not_is_max = True if not not_is_max: print(-1) return # k = 2, 3なのでk=2ができるかをベースにけんとうする for p, v_array in all_primes.items(): p_set = {p} for i0 in v_array[1]: for p, e in primes[i0].items(): if all_primes[p][0] == e: p_set.add(p) if len(p_set) != len(all_primes): print(2) v_flg = [0] * N for j in v_array[1]: v_flg[j] = 1 ans_array1 = [len(v_array[1])] ans_array2 = [N - len(v_array[1])] for j in range(N): if v_flg[j] == 1: ans_array1.append(calc_s(primes, j)) else: ans_array2.append(calc_s(primes, j)) print(" ".join(map(str, ans_array1))) print(" ".join(map(str, ans_array2))) return # k = 3のパターン target_v_array = None for p, v_array in all_primes.items(): target_v_array = v_array break i0 = target_v_array[1][0] target_p = -1 target_e = -1 for p, e_array in all_primes.items(): if p not in primes[i0] or primes[i0][p] < e_array[0]: target_p = p target_e = e_array[0] break i_set1 = set() i_set2 = set() for i in target_v_array[1]: if target_p not in primes[i] or primes[i][target_p] < target_e: i_set1.add(i) else: i_set2.add(i) i_set3 = set() for i in range(N): if i not in i_set1 and i not in i_set2: i_set3.add(i) print(3) i_array1 = [len(i_set1)] for s in i_set1: i_array1.append(calc_s(primes, s)) i_array2 = [len(i_set2)] for s in i_set2: i_array2.append(calc_s(primes,s)) i_array3 = [len(i_set3)] for s in i_set3: i_array3.append(calc_s(primes, s)) print(" ".join(map(str, i_array1))) print(" ".join(map(str, i_array2))) print(" ".join(map(str, i_array3))) if __name__ == "__main__": main()