結果

問題 No.2187 三立法和 mod 333
ユーザー lam6er
提出日時 2025-03-31 17:52:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,409 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 76,816 KB
最終ジャッジ日時 2025-03-31 17:53:36
合計ジャッジ時間 13,833 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 TLE * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read
    A = int(input().strip())
    
    K = 4444 ** 4  # 4444^4 is the sum limit
    
    # Precompute residues and x^4 values
    residues = {}
    for x in range(1, 4444):
        r = pow(x, 3, 333)
        x4 = x ** 4
        if r not in residues:
            residues[r] = []
        residues[r].append(x4)
    
    # Sort each residue list
    for r in residues:
        residues[r].sort()
    
    total = 0
    # Iterate over all a and b residues
    for a in range(333):
        alist = residues.get(a, [])
        if not alist:
            continue
        for b in range(333):
            blist = residues.get(b, [])
            if not blist:
                continue
            # Compute c residue
            c = (A - a - b) % 333
            clist = residues.get(c, [])
            if not clist:
                continue
            # Check all x in a, y in b
            current = 0
            for x4 in alist:
                for y4 in blist:
                    s_xy = x4 + y4
                    if s_xy > K:
                        continue
                    remaining = K - s_xy
                    # Count z4 in clist <= remaining
                    cnt = bisect.bisect_right(clist, remaining)
                    current += cnt
            total += current
    print(total)
    
if __name__ == '__main__':
    main()
0