結果
| 問題 |
No.2187 三立法和 mod 333
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 16:31:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,253 bytes |
| コンパイル時間 | 349 ms |
| コンパイル使用メモリ | 81,912 KB |
| 実行使用メモリ | 76,380 KB |
| 最終ジャッジ日時 | 2025-04-16 16:33:10 |
| 合計ジャッジ時間 | 5,583 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 TLE * 20 |
ソースコード
import sys
def main():
A = int(sys.stdin.readline())
T = 4444 ** 4
# Precompute cube residues and sorted s_y lists
cube_residues = [[] for _ in range(333)]
for y in range(1, 4445):
r = pow(y, 3, 333)
s = y ** 4
cube_residues[r].append(s)
# Sort each residue's list
for r in range(333):
cube_residues[r].sort()
total = 0
for x in range(1, 4445):
rx = pow(x, 3, 333)
sx = x ** 4
if sx > T:
continue
T_remaining = T - sx
req = (A - rx) % 333
current_total = 0
for r1 in range(333):
r2 = (req - r1) % 333
list1 = cube_residues[r1]
list2 = cube_residues[r2]
if not list1 or not list2:
continue
# Two-pointer technique
j = len(list2) - 1
count = 0
for i in range(len(list1)):
if list1[i] > T_remaining:
break
while j >= 0 and (list1[i] + list2[j] > T_remaining):
j -= 1
count += j + 1
current_total += count
total += current_total
print(total)
if __name__ == "__main__":
main()
lam6er