結果
問題 | No.518 ローマ数字の和 |
ユーザー |
|
提出日時 | 2022-10-15 02:34:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,121 bytes |
コンパイル時間 | 2,372 ms |
コンパイル使用メモリ | 213,952 KB |
最終ジャッジ日時 | 2025-02-08 06:00:05 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#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;}}