結果

問題 No.518 ローマ数字の和
ユーザー treeonetreeone
提出日時 2017-05-28 22:29:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,537 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 162,160 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 14:22:53
合計ジャッジ時間 2,210 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

const int INF = 1e8;
int d[7] = {1, 5, 10, 50, 100, 500, 1000};
string str = "IVXLCDM";

int change_10(string s){
    int res = 0;
    int now, pre = INF;
    rep(i, 0, s.size()){
        int id = str.find(s[i]);
        now = d[id];
        if(pre < now ){
            res += now - pre;
            pre = INF;
        }else{
            if(pre != INF) res += pre;
            pre = now;
        }
    }
    if(pre != INF) res += pre;
    return res;
}

signed main(){
    int n;
    cin >> n;
    int sum = 0;
    rep(i, 0, n){
        string s;
        cin >> s;
        int tmp = change_10(s);
        sum += tmp;
        // cout << tmp << endl;
    }
    if(sum >= 4000){
        cout << "ERROR" << endl;
        return 0;
    }
    string ans = "";
    repb(i, 6, 0){
        if(sum < d[i]) continue;
        int q = sum / d[i];
        sum %= d[i];
        // cout <<d[i] << " " << q << " "<< sum << endl;
        string tmp = "";
        if(q == 4){
            tmp += str[i];
            tmp += str[i + 1];
            // cout << 1 <<  " " << tmp << endl;
        }else{
            rep(j, 0, q){
                tmp += str[i];
            }
        }
        // cout << tmp << endl;
        ans += tmp;
    }
    cout << ans << endl;
}
0