問題一覧 > 通常問題

No.3363 Two Closest Numbers

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 40
作問者 : rurun / テスター : cho435 jupiter_68 fken_prime_57 noya2
お気に入りにしたユーザー ProblemId : 12803 / 自分の提出
問題文最終更新日: 2025-11-17 02:34:13
Two Closest Numbers
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 作問ハッカソンコンテスト 003 Day2 (順位表) の他の問題:

Problem Statement

You are given $\,N\,$ digits $\,c_1, c_2 \ldots , c_N\,$. Each $\,c_i \, (i=1, 2, \ldots , N)\,$ is one of the digits from 1 to 9.
Split these digits into $\,2\,$ groups and concatenate each group in an arbitrary order to form $\,2\,$ decimal numbers $\,X, Y\,$.

More formally, it is as follows.
Let $\,c_i'\,$ be the number corresponding to the digit $\,c_i \, (i=1, 2, \ldots , N)\,$. Given a choice of a permutation $\,P=(p_1, p_2, \ldots , p_N)\,$ of length $\,N\,$ and an integer $\,k\,(1 \leq k \leq N-1)\,$, $\,X, Y\,$ are defined as $\,X = \displaystyle{\sum_{i=1}^{k} c_{p_i}' 10^{k-i} } , Y = \displaystyle{\sum_{i=k+1}^{N} c_{p_i}' 10^{N-i} }\,$.

Find the minimum value of $\,|X-Y|\,$.
Since the answer can be very large, output the answer modulo $\,998244353\,$.

Constraints

  • $\,N\,$ is an integer
  • $\,2 \leq N \leq 2 \times 10^5\,$
  • $\,c_i\,$ is one of 1 2 3 4 5 6 7 8 9

Input

The input is given from standard input in the following format.

$N$
$c_1$ $c_2$ $\cdots$ $c_N$

Output

Output the answer modulo $\,998244353\,$.

Sample

Sample 1
Input
3
4 1 8
Output
6

There are 12 pairs of numbers $\,(X, Y) \,$ that can be formed in total. Among them, $\,(X, Y)=(8, 14),(14, 8)\,$ give $\,|X-Y| = 6\,$, which is the minimum.

Sample 2
Input
4
6 2 8 7
Output
4

For example, $\,(X, Y) = (68, 72)$ gives $\,|X-Y| = 4\,$, which is the minimum.

Sample 3
Input
6
3 1 4 1 5 9
Output
4

For example, $\,(X, Y) = (149, 153)\,$ gives $\,|X-Y| = 4\,$, which is the minimum.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。