結果

問題 No.3308 One-time Changed Formula
コンテスト
ユーザー detteiuu
提出日時 2025-10-24 21:37:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 82,712 KB
実行使用メモリ 113,276 KB
最終ジャッジ日時 2025-10-24 21:37:37
合計ジャッジ時間 4,173 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.set_int_max_str_digits(0)

for _ in range(int(input())):
    N = int(input())
    F = input()

    A = ["+"]
    B = []
    for f in F:
        if f.isdigit():
            B.append(f)
        else:
            A.append("".join(B))
            B = []
            A.append(f)
    A.append("".join(B))

    ans = 0
    pre = "+"
    for i in range(1, len(A)):
        if A[i][0].isdigit():
            for a in A[i]:
                if pre == "+":
                    ans += 9-int(a)
                else:
                    ans += int(a)-1
        elif A[i] in ["+", "-"]:
            if pre == "+":
                ans += 9
            pre = A[i]
        else:
            SUM = int(A[i-1])*int(A[i+1])
            for j in range(1, 10):
                if pre == "+" and SUM < int(A[i-1]+str(j)+A[i+1]):
                    ans += 1
                elif pre == "-" and int(A[i-1]+str(j)+A[i+1]) < SUM:
                    ans += 1
    
    print(ans)
0