結果

問題 No.2734 Addition and Multiplication in yukicoder (Hard)
ユーザー ks2mks2m
提出日時 2024-04-19 22:37:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,786 bytes
コンパイル時間 3,541 ms
コンパイル使用メモリ 80,580 KB
実行使用メモリ 95,736 KB
最終ジャッジ日時 2024-04-19 22:38:41
合計ジャッジ時間 42,632 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
37,328 KB
testcase_01 AC 51 ms
37,292 KB
testcase_02 AC 52 ms
37,436 KB
testcase_03 AC 52 ms
37,224 KB
testcase_04 AC 52 ms
37,296 KB
testcase_05 AC 51 ms
37,192 KB
testcase_06 AC 51 ms
36,804 KB
testcase_07 AC 51 ms
37,376 KB
testcase_08 AC 50 ms
37,328 KB
testcase_09 AC 49 ms
37,128 KB
testcase_10 AC 49 ms
37,380 KB
testcase_11 AC 49 ms
37,208 KB
testcase_12 AC 49 ms
37,484 KB
testcase_13 AC 60 ms
37,056 KB
testcase_14 AC 50 ms
37,228 KB
testcase_15 AC 51 ms
36,948 KB
testcase_16 AC 60 ms
37,204 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 123 ms
42,968 KB
testcase_20 AC 94 ms
41,304 KB
testcase_21 AC 100 ms
41,228 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 904 ms
58,184 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		List<List<String>> list = new ArrayList<>(20);
		for (int i = 0; i < 20; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n; i++) {
			list.get(sa[i].length()).add(sa[i]);
		}
		br.close();

		int[] size = new int[20];
		for (int i = 0; i < 20; i++) {
			size[i] = list.get(i).size();
			Collections.sort(list.get(i));
		}

		int mod = 998244353;
		StringBuilder sb = new StringBuilder();
		int[] idx = new int[20];
		for (int i = 0; i < n - 1; i++) {
			String min = "999999999999999999999";
			int minj = 0;
			for (int j = 1; j < 20; j++) {
				for (int j2 = 1; j2 < 20; j2++) {
					if (idx[j] >= size[j]) {
						continue;
					}
					if (j == j2) {
						if (idx[j] + 1 < size[j]) {
							String s = list.get(j).get(idx[j])
									+ list.get(j).get(idx[j] + 1);
							if (s.compareTo(min) < 0) {
								min = s;
								minj = j;
							}
						}
					} else {
						if (idx[j2] < size[j2]) {
							String s = list.get(j).get(idx[j])
									+ list.get(j2).get(idx[j2]);
							if (s.compareTo(min) < 0) {
								min = s;
								minj = j;
							}
						}
					}
				}
			}
			sb.append(list.get(minj).get(idx[minj]));
			idx[minj]++;
		}
		for (int j = 1; j < 20; j++) {
			if (idx[j] < size[j]) {
				sb.append(list.get(j).get(idx[j]));
				break;
			}
		}

		long ans = 0;
		for (int i = 0; i < sb.length(); i++) {
			int d = sb.charAt(i) - '0';
			ans *= 10;
			ans += d;
			ans %= mod;
		}
		System.out.println(ans);
	}
}
0