結果

問題 No.2734 Addition and Multiplication in yukicoder (Hard)
ユーザー rlangevin
提出日時 2024-04-19 23:15:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 711 ms / 5,000 ms
コード長 738 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 147,008 KB
最終ジャッジ日時 2024-10-11 17:41:44
合計ジャッジ時間 15,371 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def merge(S, T):
    Q = deque()
    for s in S:
        Q.append(s)
    for t in T[::-1]:
        Q.append(t)
    L = []
    while len(Q) >= 2:
        a = Q[0]
        b = Q[-1]
        if str(a) + str(b) <= str(b) + str(a):
            L.append(Q.popleft())
        else:
            L.append(Q.pop())
    L.append(Q.pop())
    return L

def mergeSort(A):
    mid = len(A)//2
    if len(A) <= 1:
        return A
    L, R = A[:mid], A[mid:]
    L = mergeSort(L)
    R = mergeSort(R)
    A = merge(L, R)
    return A    

N = int(input())
A = list(input().split())
M = 65
A = mergeSort(A)

ans = 0
mod = 998244353
for a in A:
    ans *= pow(10, len(a), mod)
    ans += int(a)
    ans %= mod
    
print(ans)
0