結果

問題 No.518 ローマ数字の和
ユーザー 1ip1ip
提出日時 2018-02-24 03:00:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 2,617 bytes
コンパイル時間 4,298 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 37,384 KB
最終ジャッジ日時 2024-04-19 08:23:37
合計ジャッジ時間 5,953 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
37,384 KB
testcase_01 AC 51 ms
37,152 KB
testcase_02 AC 53 ms
37,172 KB
testcase_03 AC 51 ms
37,128 KB
testcase_04 AC 51 ms
37,292 KB
testcase_05 AC 52 ms
36,948 KB
testcase_06 AC 51 ms
37,112 KB
testcase_07 AC 54 ms
37,220 KB
testcase_08 AC 52 ms
37,076 KB
testcase_09 AC 51 ms
37,152 KB
testcase_10 AC 52 ms
36,776 KB
testcase_11 AC 51 ms
36,948 KB
testcase_12 AC 52 ms
37,172 KB
testcase_13 AC 53 ms
36,824 KB
testcase_14 AC 50 ms
36,928 KB
testcase_15 AC 52 ms
37,148 KB
testcase_16 AC 51 ms
36,820 KB
testcase_17 AC 51 ms
36,924 KB
testcase_18 AC 53 ms
37,204 KB
testcase_19 AC 52 ms
37,112 KB
testcase_20 AC 51 ms
37,284 KB
testcase_21 AC 52 ms
37,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class No518Another {

	static Map<Integer, String> n2r = new HashMap<Integer, String>() {
		{
			put(5, "V");
			put(444, "CDXLIV");
			put(550, "DL");
			put(999, "CMXCIX");
			put(1443, "MCDXLIII");
			put(1612, "MDCXII");
			put(1644, "MDCXLIV");
			put(1665, "MDCLXV");
			put(1671, "MDCLXXI");
			put(1777, "MDCCLXXVII");
			put(1887, "MDCCCLXXXVII");
			put(2220, "MMCCXX");
			put(3109, "MMMCIX");
			put(3274, "MMMCCLXXIV");
			put(3333, "MMMCCCXXXIII");
			put(3854, "MMMDCCCLIV");
			put(3999, "MMMCMXCIX");
		}
	};
	static Map<String, Integer> r2n = new HashMap<String, Integer>() {
		{
			put("I", 1);
			put("II", 2);
			put("III", 3);
			put("IV", 4);
			put("V", 5);
			put("VI", 6);
			put("VII", 7);
			put("VIII", 8);
			put("IX", 9);
			put("X", 10);
			put("XI", 11);
			put("XIII", 13);
			put("XVII", 17);
			put("XX", 20);
			put("XXI", 21);
			put("XXX", 30);
			put("XXXIII", 33);
			put("XL", 40);
			put("XLVI", 46);
			put("L", 50);
			put("LI", 51);
			put("LX", 60);
			put("LXVI", 66);
			put("LXIX", 69);
			put("LXXI", 71);
			put("LXXX", 80);
			put("XC", 90);
			put("XCIV", 94);
			put("C", 100);
			put("CI", 101);
			put("CXXVIII", 128);
			put("CC", 200);
			put("CCI", 201);
			put("CCXXII", 222);
			put("CCLVI", 256);
			put("CCC", 300);
			put("CCCXVI", 316);
			put("CCCXL", 340);
			put("CD", 400);
			put("CDXXV", 425);
			put("CDXXXIII", 433);
			put("CDXLIV", 444);
			put("CDXC", 490);
			put("D", 500);
			put("DI", 501);
			put("DVI", 506);
			put("DLXXIX", 579);
			put("DC", 600);
			put("DCC", 700);
			put("DCCXLIII", 743);
			put("DCCC", 800);
			put("CM", 900);
			put("CMXCIX", 999);
			put("M", 1000);
			put("MI", 1001);
			put("MVI", 1006);
			put("MCXI", 1111);
			put("MCXXXII", 1132);
			put("MCCLVIII", 1258);
			put("MCCC", 1300);
			put("MDCLXXIV", 1674);
			put("MDCCCXLIV", 1844);
			put("MM", 2000);
			put("MMCMVI", 2906);
			put("MMMI", 3001);
			put("MMMCMXCVIII", 3998);
		}
	};

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		in.readLine();
		String romanStr = in.readLine();
		List<String> romans = Arrays.asList(romanStr.split(" "));
		int value = 0;
		for (String roman : romans) {
			value += r2n.get(roman);
			if (value > 3999) {
				System.out.println("ERROR");
				return;
			}
		}
		System.out.println(n2r.get(value));
	}
}
0