結果

問題 No.518 ローマ数字の和
ユーザー uchiiiiuchiiii
提出日時 2020-08-20 02:38:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,845 bytes
コンパイル時間 4,906 ms
コンパイル使用メモリ 225,492 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 18:28:23
合計ジャッジ時間 6,746 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
template<class T>inline T emod(T a, T p) { return (a%p + p) % p;}
//-------------------
map<char, int> mp = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
vector<char> v = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
int rom2int() {
    string s; cin >> s;
    int sm = 0;
    rep(i, s.size()) {
        if(i < s.size()-1 and mp[s[i]] < mp[s[i+1]]) {
            sm -= mp[s[i]];
        } else {
            sm += mp[s[i]];
        }
    }
    return sm;
}

void int2rom(int k) {
    rep(i, v.size()) {
        int cur = k / mp[v[i]];
        if(cur == 4) {
            cout << v[i] << v[i-1];
        } else {
            rep(_, cur) cout << v[i];
        }
        k -= cur * mp[v[i]];
    }
    cout << endl;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    int n; cin >> n;

    reverse(ALL(v));
    int sm = 0;    
    rep(i, n) {
        sm += rom2int();
    }
    // cout << sm << endl;
    if(sm >= 4000) cout << "ERROR" << endl;
    else {
        int2rom(sm);
    }
    return 0;
}
0