QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763342 | #8048. Roman Master | yangjl | WA | 92ms | 3872kb | C++20 | 1.4kb | 2024-11-19 19:40:40 | 2024-11-19 19:40:41 |
Judging History
answer
/**
* author: yangjl
* created: 2024.11.19 19:25:06
**/
#include <bits/stdc++.h>
#ifdef YJL
#include "debug.h"
#else
#define debug(...)0
#endif
using namespace std;
using ll = long long;
template<class T>
istream& operator>>(istream& is, vector<T>& v) {
for(auto& x : v) {
is >> x;
}
return is;
}
// IIIVIII
const string roman[8] = {"I","II","III","IV","V","VI","VII","VII"};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int tt;
cin >> tt;
while(tt--) {
string s;
cin >> s;
int const n = s.size();
vector<int> f(n + 1, n);
f[n] = 0;
for(int i = n - 1; i >= 0; --i) {
for(string const& p : roman) {
if(i + p.size() <= n and s.substr(i, p.size()) == p) {
f[i] = min(f[i], 1 + f[i + p.size()]);
}
}
}
for(int i = 0; i < n; ) {
for(int j = 0; j < 8; ++j) {
string const& p = roman[j];
if(i + p.size() <= n and s.substr(i, p.size()) == p
and f[i] == 1 + f[i + p.size()]) {
cout << char('0' + j + 1);
i += p.size();
break;
}
}
}
cout << "\n";
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
3 II IVI VIIIIIV
output:
2 16 634
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 92ms
memory: 3872kb
input:
100000 VVIVVVVVII VVVIIIIVVI IVIIVIIIIV VVVVVIIVVI IIIVIVVVIV VIVIIIIIVI VVIIVVIVVI IVVVIVVVVV VIIVVVVIVV VIIIIVVVVV VVVVVVIVIV VIVIIIVVVI VIIIVIVVVI VIIIIVVIIV VIVVVIIVII IIIIIVIIVI IIIIVVVVII IVIIVVIIVI IVVIVVIIIV IVVVIIIVIV IIIIVIIIVV VVVVVIVIIV VVVIIIIVVV VIVVIIIIVI VIIIIIIIIV VIVIVVVIVV IVIIIVI...
output:
5545557 555346 16434 5555646 244554 6736 564546 45545555 6455545 5345555 55555544 67456 74456 53464 54577 2376 34557 16476 45474 45744 13745 5555664 5553455 54636 6334 5445545 4363 27645 34645 54746 55556455 46345 3746 74546 6633 5455544 6343 4776 53666 1455445 555555556 44444 456445 5733 4743 54555...
result:
wrong answer 2nd lines differ - expected: '55846', found: '555346'