結果

問題 No.518 ローマ数字の和
ユーザー rogi52rogi52
提出日時 2022-10-15 02:34:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 219,448 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 01:58:19
合計ジャッジ時間 4,993 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    map<string,int> mp = {
        {"I",    1},
        {"V",    5},
        {"X",   10},
        {"L",   50},
        {"C",  100},
        {"D",  500},
        {"M", 1000},
        {"IV",    5 -   1},
        {"IX",   10 -   1},
        {"XL",   50 -  10},
        {"XC",  100 -  10},
        {"CD",  500 - 100},
        {"CM", 1000 - 100}
    };
    map<int,string> inv;
    for(auto [s, n] : mp) inv[-n] = s;

    int N; cin >> N;
    int sumR = 0;
    rep(i,N) {
        string s; cin >> s;
        vector<int> a;
        for(char c : s) a.push_back(mp[string(1, c)]);
        rep(i,a.size()-1) if(a[i] < a[i + 1]) a[i] *= -1;
        sumR += accumulate(a.begin(), a.end(), 0);
    }

    if(sumR > 3999) {
        cout << "ERROR" << endl;
    } else {
        string ans = "";
        for(auto [n, s] : inv) {
            int x = -n;
            rep(_,sumR/x) ans += s;
            sumR %= x;
        }
        cout << ans << endl;
    }
}
0