#abc221c. C - Select Mul

C - Select Mul

Score : 300300 points

问题描述

给定一个整数 NN。考虑将 NN 的各位数字进行排列,并将其分割成两个 正整数

例如,对于整数 123123,有六种分割方式如下:

  • 121233
  • 212133
  • 131322
  • 313122
  • 232311
  • 323211

这里,分割后的两个整数中不能包含前导零。例如,不允许将整数 101101 分割为 110101。另外,由于得到的两个整数必须为正数,也不允许将 101101 分割为 111100

通过最优分割方式能得到的最大可能的两个结果整数之积是多少?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given an integer NN. Consider permuting the digits in NN and separate them into two positive integers.

For example, for the integer 123123, there are six ways to separate it, as follows:

  • 1212 and 33,
  • 2121 and 33,
  • 1313 and 22,
  • 3131 and 22,
  • 2323 and 11,
  • 3232 and 11.

Here, the two integers after separation must not contain leading zeros. For example, it is not allowed to separate the integer 101101 into 11 and 0101. Additionally, since the resulting integers must be positive, it is not allowed to separate 101101 into 1111 and 00, either.

What is the maximum possible product of the two resulting integers, obtained by the optimal separation?

Constraints

  • NN is an integer between 11 and 10910^9 (inclusive).
  • NN contains two or more digits that are not 00.

Input

Input is given from Standard Input in the following format:

NN

Output

Print the maximum possible product of the two integers after separation.

Sample Input 1

123

Sample Output 1

63

As described in Problem Statement, there are six ways to separate it:

  • 1212 and 33,
  • 2121 and 33,
  • 1313 and 22,
  • 3131 and 22,
  • 2323 and 11,
  • 3232 and 11.

The products of these pairs, in this order, are 3636, 6363, 2626, 6262, 2323, 3232, with 6363 being the maximum.

Sample Input 2

1010

Sample Output 2

100

There are two ways to separate it:

  • 100100 and 11,
  • 1010 and 1010.

In either case, the product is 100100.

Sample Input 3

998244353

Sample Output 3

939337176

update @ 2024/3/10 09:44:55