結果

問題 No.2734 Addition and Multiplication in yukicoder (Hard)
ユーザー rlangevinrlangevin
提出日時 2024-04-20 00:37:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 607 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 146,264 KB
最終ジャッジ日時 2024-04-20 00:37:20
合計ジャッジ時間 12,098 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,632 KB
testcase_01 AC 38 ms
53,760 KB
testcase_02 AC 37 ms
54,272 KB
testcase_03 AC 44 ms
53,632 KB
testcase_04 AC 38 ms
53,888 KB
testcase_05 AC 36 ms
53,760 KB
testcase_06 AC 37 ms
53,632 KB
testcase_07 AC 37 ms
53,632 KB
testcase_08 AC 37 ms
54,016 KB
testcase_09 AC 36 ms
53,888 KB
testcase_10 AC 38 ms
53,632 KB
testcase_11 AC 36 ms
53,760 KB
testcase_12 AC 35 ms
53,504 KB
testcase_13 AC 37 ms
53,760 KB
testcase_14 AC 35 ms
53,760 KB
testcase_15 AC 36 ms
54,144 KB
testcase_16 AC 38 ms
53,632 KB
testcase_17 AC 529 ms
128,728 KB
testcase_18 AC 507 ms
128,344 KB
testcase_19 AC 38 ms
55,040 KB
testcase_20 AC 38 ms
54,912 KB
testcase_21 AC 37 ms
54,656 KB
testcase_22 AC 576 ms
140,488 KB
testcase_23 AC 535 ms
140,296 KB
testcase_24 AC 538 ms
140,248 KB
testcase_25 AC 593 ms
140,120 KB
testcase_26 AC 546 ms
140,248 KB
testcase_27 AC 590 ms
146,264 KB
testcase_28 AC 559 ms
140,652 KB
testcase_29 AC 607 ms
141,780 KB
testcase_30 AC 548 ms
143,296 KB
testcase_31 AC 562 ms
144,904 KB
testcase_32 AC 555 ms
138,772 KB
testcase_33 AC 406 ms
119,676 KB
testcase_34 AC 493 ms
131,460 KB
testcase_35 AC 288 ms
105,840 KB
testcase_36 AC 315 ms
107,192 KB
testcase_37 AC 411 ms
121,968 KB
testcase_38 AC 450 ms
122,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def cmp_to_key(a, b):
    return a + b <= b + a

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:
        if cmp_to_key(Q[0], Q[-1]):
            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())
A = mergeSort(A)
ans = 0
mod = 998244353
M = 20
ten = [1] * M
for i in range(1, M):
    ten[i] = (ten[i - 1] * 10) % mod
for a in A:
    ans = (ans * ten[len(a)] + int(a)) % mod
    
print(ans)
0