結果
問題 | No.3033 エルハートの数え上げ |
ユーザー |
![]() |
提出日時 | 2025-02-21 22:16:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 481 ms / 2,000 ms |
コード長 | 1,444 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 82,240 KB |
実行使用メモリ | 90,404 KB |
最終ジャッジ日時 | 2025-02-21 22:16:23 |
合計ジャッジ時間 | 8,498 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
class Lagrange:def __init__(self, X, Y):from fractions import Fractionassert len(X) == len(Y)assert len(set(X)) == len(X)N = len(X)self.C = C = []for i in range(N):res = 1for j in range(N):if i == j:continueres *= X[i] - X[j]c = Fraction(Y[i], res)C.append(c)self.X, self.Y = X, Yself.d = {x: y for x, y in zip(X, Y)}def __call__(self, x):from fractions import Fractionres = self.d.get(x)if res is not None:return resbase = 1for a in self.X:base *= x-ares = 0for a, c in zip(self.X, self.C):res += Fraction(base, x-a) * cif res == int(res):return int(res)return resdef is_in(x,y,z,a,b,c,d):return a*x+b*y+c*z+d >= 0MOD = 998_244_353N, M = map(int, input().split())ABCD = []for _ in range(M):a, b, c, d = map(int, input().split())ABCD.append((a, b, c, d))def naive(N):C = 15res = 0for x in range(-C*N, C*N + 1):for y in range(-C*N, C*N + 1):for z in range(-C*N, C*N + 1):for a, b, c, d in ABCD:if not is_in(x, y, z, a, b, c, d*N):breakelse:res += 1return resd = 3X = [0, 1, 2, 3]L = Lagrange(X, list(map(naive, X)))ans = (-1)**d * L(-N)print(ans%MOD)