結果

問題 No.518 ローマ数字の和
ユーザー te-shte-sh
提出日時 2018-01-26 11:24:22
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 93,244 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 18:22:19
合計ジャッジ時間 2,171 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,388 KB
testcase_21 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;}
T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;}

void main()
{
  int n; readV(n);
  auto r = readArray!string(n);

  auto f = new int[](n);

  auto tbl1 = ['I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000];
  foreach (i, ri; r) {
    auto a = ri.map!(c => tbl1[cast(char)c]).array;
    foreach (j; 0..a.length-1)
      if (a[j+1] > a[j]) a[j] = -a[j];
    f[i] = a.sum;
  }

  auto s = f.sum;

  if (s > 3999) {
    writeln("ERROR");
    return;
  }

  auto tbl2 = [["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"],
               ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"],
               ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"],
               ["", "M", "MM", "MMM"]];
  foreach_reverse (i; 0..4) {
    auto d = s%10^^(i+1)/10^^i;
    write(tbl2[i][d]);
  }

  writeln;
}
0