問題一覧 > 通常問題

No.10 +か×か

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 265
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 29 / 自分の提出
問題文最終更新日: 2026-06-25 08:44:02
+ or ×
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 10 (順位表) の他の問題:

Problem Statement

You are trying to copy a notebook you borrowed from Isaac by running it through OCR.
When you ran OCR on a certain expression, you noticed that the operators were not recognized correctly and had been garbled.
The only operators appearing here are + and *, and all of them are displayed as ?.
Find the correct original expression.
If there are multiple answers, find the first one in lexicographic order with respect to the order {+,*}.
For example, the lexicographic order is
++ \(\rightarrow\) +* \(\rightarrow\) *+ \(\rightarrow\) ** in this order.

Important: in this problem, the operators have the same precedence and are left-associative.
Simply put, the operations are just processed in order from the left.
For example, for 1 ? 2 ? 10 ? 1=31, the answer is 1+2*10+1,
which is evaluated as ((1+2)*10)+1=31 in real-world notation, so be careful.

Input

\(N\)
\(Total\)
\(A_1\ A_2\ \dots\ A_N\)

The \(1\)st line contains \(N\ (2 \leq N \leq 50) \), the number of integers in the expression.
The \(2\)nd line contains \( Total\ (1 \leq Total \leq 100,000) \), the result of the expression.
The \(3\)rd line contains \(N\) space-separated integers \( A_i\ (1 \leq A_i \leq 10) \), the integers in the expression.

It is guaranteed that there is at least one solution satisfying
A1 ? A2 ? A3 ?....? AN = Total.

Output

Output the operators arranged in order.
(Do not add delimiters such as spaces.)
Print a newline at the end.

Sample

Sample 1
Input
4
31
1 2 10 1
Output
+*+

Sample 2
Input
3
6
2 3 1
Output
++

** also works, but the answer is ++ because it comes first in lexicographic order with respect to {+*}.

Sample 3
Input
3
2
1 1 2
Output
**

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