結果
問題 | No.1358 [Zelkova 2nd Tune *] 語るなら枚数を... |
ユーザー | 👑 SPD_9X2 |
提出日時 | 2021-01-22 23:08:33 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,312 bytes |
コンパイル時間 | 279 ms |
コンパイル使用メモリ | 86,944 KB |
実行使用メモリ | 79,420 KB |
最終ジャッジ日時 | 2023-08-27 21:59:14 |
合計ジャッジ時間 | 6,067 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 113 ms
76,968 KB |
testcase_01 | AC | 78 ms
75,528 KB |
testcase_02 | AC | 80 ms
75,648 KB |
testcase_03 | AC | 81 ms
75,468 KB |
testcase_04 | AC | 77 ms
75,556 KB |
testcase_05 | AC | 79 ms
75,376 KB |
testcase_06 | AC | 229 ms
78,496 KB |
testcase_07 | AC | 199 ms
78,024 KB |
testcase_08 | AC | 253 ms
79,420 KB |
testcase_09 | AC | 215 ms
78,104 KB |
testcase_10 | AC | 230 ms
78,848 KB |
testcase_11 | TLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
ソースコード
""" """ import sys from sys import stdin import math def extGCD(a,b): if b: d,y,x = extGCD(b,a % b) y -= a // b * x return d,x,y return a,1,0 TT = int(stdin.readline()) mod = 10**9+7 ans = 0 for loop in range(TT): N,K,H,Y = map(int,stdin.readline().split()) A = [N,K,H] A.sort() A.reverse() ans = 0 for i in range(0,Y // A[0] + 1): rem = Y - A[0] * i #print (rem) a,b = A[1],A[2] g,x,y = extGCD(a,b) if rem % g != 0: continue x *= rem // g y *= rem // g lcm = a * b // g p = lcm // a q = lcm // b #xをp増やし、yをq減らす #xをp減らし、yをq増やす ができる if x >= 0: move = x // p xa,ya = x - move * p , y + move * q else: move = (abs(x)+p-1) // p xa,ya = x + move * p , y - move * q if y >= 0: move = y // q xb,yb = x + move * p, y - move * q else: move = (abs(y)+q-1) // q xb,yb = x - move * p , y + move * q if ya < 0 or xb < 0: continue #print (rem , xa , ya , xb , yb) ans += max(0 , (xb - xa) // p + 1) ans %= mod print (ans)