結果
問題 | No.518 ローマ数字の和 |
ユーザー | anta |
提出日時 | 2017-05-28 21:27:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,546 bytes |
コンパイル時間 | 1,740 ms |
コンパイル使用メモリ | 176,968 KB |
実行使用メモリ | 4,348 KB |
最終ジャッジ日時 | 2023-10-21 14:02:37 |
合計ジャッジ時間 | 2,902 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge10 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,348 KB |
testcase_01 | AC | 3 ms
4,348 KB |
testcase_02 | AC | 3 ms
4,348 KB |
testcase_03 | AC | 3 ms
4,348 KB |
testcase_04 | AC | 3 ms
4,348 KB |
testcase_05 | AC | 4 ms
4,348 KB |
testcase_06 | AC | 4 ms
4,348 KB |
testcase_07 | AC | 3 ms
4,348 KB |
testcase_08 | AC | 3 ms
4,348 KB |
testcase_09 | AC | 3 ms
4,348 KB |
testcase_10 | AC | 4 ms
4,348 KB |
testcase_11 | AC | 4 ms
4,348 KB |
testcase_12 | AC | 3 ms
4,348 KB |
testcase_13 | AC | 4 ms
4,348 KB |
testcase_14 | AC | 3 ms
4,348 KB |
testcase_15 | AC | 3 ms
4,348 KB |
testcase_16 | AC | 3 ms
4,348 KB |
testcase_17 | AC | 3 ms
4,348 KB |
testcase_18 | AC | 3 ms
4,348 KB |
testcase_19 | AC | 4 ms
4,348 KB |
testcase_20 | AC | 3 ms
4,348 KB |
testcase_21 | AC | 3 ms
4,348 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll; template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; } void toRomanNumber1(char i, char v, char x, int n, string &s) { switch (n) { case 0: break; case 1: s += i; break; case 2: s += i, s += i; break; case 3: s += i, s += i, s += i; break; case 4: s += i, s += v; break; case 5: s += v; break; case 6: s += v, s += i; break; case 7: s += v, s += i, s += i; break; case 8: s += v, s += i, s += i, s += i; break; case 9: s += i, s += x; break; default: break; } } string toRomanNumber(int n) { string s(n / 1000, 'M'); toRomanNumber1('C', 'D', 'M', n / 100 % 10, s); toRomanNumber1('X', 'L', 'C', n / 10 % 10, s); toRomanNumber1('I', 'V', 'X', n % 10, s); return s; } int main() { map<string, int> a; rer(i, 1, 3999) { a[toRomanNumber(i)]=i; } int N; while (~scanf("%d", &N)) { int sum = 0; rep(i, N) { char buf[101]; scanf("%s", buf); sum+=a[buf]; } if (sum > 3999) { puts("ERROR"); } else { string ans = toRomanNumber(sum); puts(ans.c_str()); } } return 0; }