QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738588 | #8048. Roman Master | UESTC_NLNS# | TL | 0ms | 3576kb | C++14 | 1.2kb | 2024-11-12 19:27:33 | 2024-11-12 19:27:38 |
Judging History
answer
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int N=100005;
int t,n,f[N];
string s;
signed main(){
cin>>t;
while(t--){
cin>>s;n=s.length();s=' '+s;//cerr<<n<<"\n";
f[n+1]=0;
for(int i=n;i>=1;--i){
f[i]=f[i+1]+1;
if(i!=n&&(s[i]!='V'||s[i+1]!='V'))f[i]=min(f[i],f[i+2]+1);
if(i+2<=n&&s[i]=='V'&&s[i+1]=='I'&&s[i+2]=='I')f[i]=min(f[i],f[i+3]+1);
if(i+2<=n&&s[i]=='I'&&s[i+1]=='I'&&s[i+2]=='I')f[i]=min(f[i],f[i+3]+1);
if(i+2<=n&&s[i]=='V'&&s[i+1]=='I'&&s[i+2]=='I'&&s[i+3]=='I')f[i]=min(f[i],f[i+4]+1);
}int la=f[1];int x=1;
while(x<=n){
if(s[x]=='I'&&la==f[x+1]+1){++x;cout<<"1";}
else if(x+1<=n&&s[x]=='I'&&s[x+1]=='I'&&la==f[x+2]+1){x+=2;cout<<"2";}
else if(x+2<=n&&s[x]=='I'&&s[x+1]=='I'&&s[x+2]=='I'&&la==f[x+3]+1){x+=3;cout<<"3";}
else if(x+1<=n&&s[x]=='I'&&s[x+1]=='V'&&la==f[x+2]+1){x+=2;cout<<"4";}
else if(s[x]=='V'&&la==f[x+1]+1){x+=1;cout<<"5";}
else if(x+1<=n&&s[x]=='V'&&s[x+1]=='I'&&la==f[x+2]+1){x+=2;cout<<"6";}
else if(x+2<=n&&s[x]=='V'&&s[x+1]=='I'&&s[x+2]=='I'&&la==f[x+3]+1){x+=3;cout<<"7";}
else if(x+3<=n&&s[x]=='V'&&s[x+1]=='I'&&s[x+2]=='I'&&s[x+3]=='I'&&la==f[x+3]+1){x+=3;cout<<"7";}
--la;
}cout<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
3 II IVI VIIIIIV
output:
2 16 634
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
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