結果
| 問題 | No.40 多項式の割り算 | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-03-20 20:53:02 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 115 ms / 5,000 ms | 
| コード長 | 1,263 bytes | 
| コンパイル時間 | 240 ms | 
| コンパイル使用メモリ | 82,284 KB | 
| 実行使用メモリ | 63,388 KB | 
| 最終ジャッジ日時 | 2025-03-20 20:53:08 | 
| 合計ジャッジ時間 | 3,198 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 32 | 
ソースコード
D = int(input())
coeff = list(map(int, input().split()))
b0 = 0
b1 = 0
b2 = 0
for i in range(D + 1):
    a_i = coeff[i]
    if i == 0:
        b0 += a_i
    elif i == 1:
        b1 += a_i
    elif i == 2:
        b2 += a_i
    else:
        if i % 2 == 1:  # 1 -> x^1
            b1 += a_i
        else:  # 0 -> x^2
            b2 += a_i
# Determine the maximum degree
max_deg = 0
coefficients = []
if b2 != 0:
    max_deg = 2
    coefficients = [b0, b1, b2]
elif b1 != 0:
    max_deg = 1
    coefficients = [b0, b1]
else:
    # Check if all are zero
    if b0 == 0:
        max_deg = 0
        coefficients = [0]
    else:
        max_deg = 0
        coefficients = [b0]
# Truncate coefficients list based on max_deg
if max_deg == 2:
    coefficients = coefficients[:3]  # [b0, b1, b2]
elif max_deg == 1:
    coefficients = coefficients[:2]  # [b0, b1]
else:
    coefficients = coefficients[:1]  # [b0]
# Now, check trailing zeros for higher degrees
# For example, if max_deg is 1 but b1 is zero due to previous steps
# But since max_deg is determined by checking non-zero, this should be handled
# Now handle the case where all are zero (but earlier handled by b0=0 -> coefficients [0])
# Now, output
print(max_deg)
print(' '.join(map(str, coefficients)))
            
            
            
        