結果
問題 | No.2620 Sieve of Coins |
ユーザー | startcpp |
提出日時 | 2023-12-15 01:35:28 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,370 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 12,288 KB |
実行使用メモリ | 71,296 KB |
最終ジャッジ日時 | 2023-12-15 01:36:22 |
合計ジャッジ時間 | 34,712 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 547 ms
50,032 KB |
testcase_01 | AC | 452 ms
43,228 KB |
testcase_02 | AC | 447 ms
43,228 KB |
testcase_03 | AC | 1,176 ms
71,296 KB |
testcase_04 | AC | 1,742 ms
71,280 KB |
testcase_05 | AC | 473 ms
43,244 KB |
testcase_06 | AC | 451 ms
43,244 KB |
testcase_07 | AC | 458 ms
43,244 KB |
testcase_08 | AC | 450 ms
43,244 KB |
testcase_09 | AC | 459 ms
43,232 KB |
testcase_10 | AC | 482 ms
43,232 KB |
testcase_11 | AC | 463 ms
43,244 KB |
testcase_12 | AC | 457 ms
43,228 KB |
testcase_13 | AC | 460 ms
43,244 KB |
testcase_14 | AC | 451 ms
43,228 KB |
testcase_15 | AC | 474 ms
43,228 KB |
testcase_16 | AC | 453 ms
43,244 KB |
testcase_17 | AC | 475 ms
43,232 KB |
testcase_18 | AC | 1,139 ms
70,728 KB |
testcase_19 | AC | 1,125 ms
71,284 KB |
testcase_20 | AC | 468 ms
43,244 KB |
testcase_21 | AC | 1,163 ms
71,284 KB |
testcase_22 | AC | 1,145 ms
71,284 KB |
testcase_23 | AC | 1,136 ms
71,280 KB |
testcase_24 | AC | 1,129 ms
71,280 KB |
testcase_25 | AC | 1,126 ms
71,280 KB |
testcase_26 | AC | 1,145 ms
71,296 KB |
testcase_27 | AC | 1,144 ms
71,052 KB |
testcase_28 | AC | 478 ms
43,228 KB |
testcase_29 | AC | 447 ms
43,228 KB |
testcase_30 | AC | 447 ms
43,232 KB |
testcase_31 | AC | 1,292 ms
71,284 KB |
testcase_32 | AC | 1,219 ms
71,284 KB |
testcase_33 | AC | 1,339 ms
71,280 KB |
testcase_34 | AC | 1,749 ms
71,284 KB |
testcase_35 | AC | 1,759 ms
71,280 KB |
testcase_36 | AC | 1,790 ms
71,280 KB |
testcase_37 | AC | 1,813 ms
71,284 KB |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
ソースコード
# numpyを使った高速化 from typing import List, Dict, Tuple import numpy as np import math def setMebius(n: int) -> np.ndarray: is_prime = np.ones(n + 1, dtype = np.int32) mebius = np.ones(n + 1, dtype = np.int32) is_prime[0] = 0 is_prime[1] = 0 for i in range(2, n + 1): if is_prime[i]: mebius[i : n + 1 : i] *= -1 mebius[i * i : n + 1 : i * i] = 0 is_prime[2 * i : n + 1 : i] = 0 return mebius def calc(L: int, noDiv2: bool, noDiv3: bool, mebius: np.ndarray) -> int: sqL: int = len(mebius) - 1 gs: np.ndarray = np.ones(sqL + 1, dtype = np.int64) * L gs[1::] //= np.arange(1, sqL + 1, dtype = np.int64) * np.arange(1, sqL + 1, dtype = np.int64) if noDiv2 and noDiv3: gs[::2] = 0 gs[::3] = 0 gs = gs - gs // 2 - gs // 3 + gs // 6 elif noDiv2: gs[::2] = 0 gs = gs - gs // 2 elif noDiv3: gs[::3] = 0 gs = gs - gs // 3 return (mebius[1:] * gs[1:]).sum() def subtask4(L: int, a: List[int], mebius: List[int]) -> int: n: int = len(a) plot: List[List[bool]] = [[False for _ in range(60)] for _ in range(60)] for i in range(n): c2: int = 0 c3: int = 0 t: int = a[i] while t % 2 == 0: t //= 2 c2 += 1 while t % 3 == 0: t //= 3 c3 += 1 plot[c2][c3] = True p2: List[int] = [1] p3: List[int] = [1] while p2[-1] <= L: p2.append(p2[-1] * 2) while p3[-1] <= L: p3.append(p3[-1] * 3) ret: int = 0 i: int = 0 mp: Dict[Tuple[int, int, int], int] = {} while p2[i] <= L: j: int = 0 while p2[i] * p3[j] <= L: tmpL: int = L // (p2[i] * p3[j]) # 選ぶ要素のLCM = p2[i] * p3[j] for k in range(16): max2: int = -1 min2: int = 1000000 max3: int = -1 min3: int = 1000000 cnt: int = 0 not_found: bool = False for l in range(4): if (k >> l) % 2 == 1: c2: int = i - l // 2 c3: int = j - l % 2 if c2 < 0 or c3 < 0 or plot[c2][c3] == False: not_found = True break max2 = max(max2, c2) min2 = min(min2, c2) max3 = max(max3, c3) min3 = min(min3, c3) cnt += 1 if not_found or cnt == 0 or max2 != i or max3 != j: continue noDiv2 = (min2 != max2) noDiv3 = (min3 != max3) key = (tmpL, noDiv2, noDiv3) if key not in mp: mp[key] = calc(tmpL, noDiv2, noDiv3, mebius) if cnt % 2 == 1: ret += mp[key] * p2[cnt - 1] else: ret -= mp[key] * p2[cnt - 1] j += 1 i += 1 return ret if __name__ == '__main__': L, N = map(int, input().split()) a = list(map(int, input().split())) sqL: int = 1 while sqL * sqL <= L: sqL += 1 sqL -= 1 mebius: List[int] = setMebius(sqL) ans: int = subtask4(L, a, mebius) print(ans)