QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#774811 | #8048. Roman Master | New_Folder# | WA | 35ms | 5668kb | C++20 | 1.4kb | 2024-11-23 13:54:26 | 2024-11-23 13:54:35 |
Judging History
answer
#pragma GCC optimize(2)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int dp[2000001];
int a[200001];
void solve(){
string s;
cin>>s;
int n=s.length();
for(int i=1;i<=n;i++){
if(s[i-1]=='I'){
a[i]=1;
}else{
a[i]=5;
}
}
dp[n]=1;
dp[n+1]=dp[n+2]=dp[n+3]=0;
for(int i=n-1;i>=1;i--){
dp[i]=dp[i+1]+1;
if(a[i]==1){
if(i<=n-2&&a[i+1]==1&&a[i+2]==1){
dp[i]=min(dp[i],dp[i+3]+1);
}
if(a[i+1]==1){
dp[i]=min(dp[i],dp[i+2]+1);
}else{
dp[i]=min(dp[i],dp[i+2]+1);
}
}else{
if(a[i+1]==1){
dp[i]=min(dp[i],dp[i+2]+1);
if(i+2<=n&&a[i+2]==1){
dp[i]=min(dp[i],dp[i+3]+1);
if(i+3<=n&&a[i+3]==1){
dp[i]=min(dp[i],dp[i+3]+1);
}
}
}
}
}
string ans="";
for(int i=1;i<=n;i++){
for(int j=i+1;j<=min(n+1,i+4);j++){
if(dp[j]==dp[i]-1){
if(j==i+1){
ans+=(char)(a[i]+'0');
}else if(j==i+2){
if(a[i]==1){
if(a[i+1]==1){
ans+="2";
}else{
ans+='4';
}
}else{
ans+="6";
}
}else if(j==i+3){
if(a[i]==1){
ans+="3";
}else{
ans+='7';
}
}else{
ans+='8';
}
i=j-1;
break;
}
}
}
for(int i=1;i<=n+1;i++){
dp[i]=0;
}
cout<<ans<<endl;
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;cin>>T;while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5668kb
input:
3 II IVI VIIIIIV
output:
2 16 634
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 3500kb
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'