結果
問題 | No.518 ローマ数字の和 |
ユーザー | 37zigen |
提出日時 | 2020-03-15 04:37:19 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 3,558 bytes |
コンパイル時間 | 1,923 ms |
コンパイル使用メモリ | 76,828 KB |
実行使用メモリ | 54,428 KB |
最終ジャッジ日時 | 2023-08-15 16:17:47 |
合計ジャッジ時間 | 6,008 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
54,220 KB |
testcase_01 | AC | 128 ms
54,400 KB |
testcase_02 | AC | 133 ms
54,200 KB |
testcase_03 | AC | 127 ms
53,624 KB |
testcase_04 | AC | 135 ms
54,200 KB |
testcase_05 | AC | 128 ms
54,188 KB |
testcase_06 | AC | 134 ms
54,200 KB |
testcase_07 | AC | 126 ms
54,200 KB |
testcase_08 | AC | 130 ms
53,908 KB |
testcase_09 | AC | 131 ms
54,200 KB |
testcase_10 | AC | 131 ms
52,052 KB |
testcase_11 | AC | 127 ms
53,720 KB |
testcase_12 | AC | 127 ms
54,260 KB |
testcase_13 | AC | 127 ms
53,960 KB |
testcase_14 | AC | 126 ms
53,724 KB |
testcase_15 | AC | 133 ms
54,124 KB |
testcase_16 | AC | 131 ms
53,896 KB |
testcase_17 | AC | 134 ms
53,616 KB |
testcase_18 | AC | 132 ms
54,068 KB |
testcase_19 | AC | 134 ms
54,428 KB |
testcase_20 | AC | 133 ms
53,472 KB |
testcase_21 | AC | 132 ms
54,172 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.HashMap; import java.util.NoSuchElementException; class Main { public static void main(String[] args) { new Main().run(); } void run() { FastScanner sc=new FastScanner(); HashMap<String,Integer> toArabic=new HashMap<String, Integer>(); HashMap<Integer,String> toRoman=new HashMap<Integer, String>(); int N=sc.nextInt(); for(int i=0;i<=3;++i) { String a=""; for(int m=0;m<i;++m) { a+="M"; } for(int j=0;j<=9;++j) { String b=""; if(j==4)b="CD"; else if(j==9)b="CM"; else { for(int m=0;m<j%5;++m) { b+="C"; } if(j>=5)b="D"+b; } for(int k=0;k<=9;++k) { String c=""; if(k==4)c="XL"; else if(k==9)c="XC"; else { for(int m=0;m<k%5;++m) { c+="X"; } if(k>=5)c="L"+c; } for(int l=0;l<=9;++l) { String d=""; if(l==4)d="IV"; else if(l==9) d="IX"; else { for(int m=0;m<l%5;++m) { d+="I"; } if(l>=5)d="V"+d; } int v=i*1000+j*100+k*10+l; toArabic.put(a+b+c+d, v); toRoman.put(v, a+b+c+d); } } } } int cur=0; for(int i=0;i<N;++i) { cur+=toArabic.get(sc.next()); } if(cur>3999) { System.out.println("ERROR"); }else { System.out.println(toRoman.get(cur)); } } void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));} } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }