QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#651702 | #8048. Roman Master | Tggdb# | WA | 17ms | 3736kb | C++20 | 1.5kb | 2024-10-18 17:56:41 | 2024-10-18 17:56:51 |
Judging History
answer
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define inf 0X7fffffff
#define int long long
using namespace std;
const int N=2e6+9;
int read(int &x){
int dat=0,oko=1;char chc=getchar();
while(chc<'0'||chc>'9'){if(chc=='-')oko=-1;chc=getchar();}
while(chc>='0'&&chc<='9'){dat=dat*10+chc-'0';chc=getchar();}
x=dat*oko;return x;
}int T,n,ans,f[N];
string s,ts;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
cin>>ts;n=ts.length();f[0]=0;
for(int i=1;i<=n;i++)f[i]=inf;
for(int i=1;i<=n;i++)s[i]=ts[i-1];
for(int i=1;i<=n;i++){
if(s[i]=='I')f[i]=min(f[i],f[i-1]*10+1);
if(s[i]=='V')f[i]=min(f[i],f[i-1]*10+5);
if(i>1){
if(s[i-1]=='I'&&s[i]=='I'){
f[i]=min(f[i],f[i-2]*10+2);
}if(s[i-1]=='I'&&s[i]=='V'){
f[i]=min(f[i],f[i-2]*10+4);
}if(s[i-1]=='V'&&s[i]=='I'){
f[i]=min(f[i],f[i-2]*10+6);
}
}if(i>2){
if(s[i-2]=='I'&&s[i-1]=='I'&&s[i]=='I'){
f[i]=min(f[i],f[i-3]*10+3);
}if(s[i-2]=='V'&&s[i-1]=='I'&&s[i]=='I'){
f[i]=min(f[i],f[i-3]*10+7);
}
}if(i>3){
if(s[i-3]=='V'&&s[i-2]=='I'&&s[i-1]=='I'&&s[i]=='I'){
f[i]=min(f[i],f[i-4]*10+8);
}
}
}cout<<f[n]<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3736kb
input:
3 II IVI VIIIIIV
output:
2 16 634
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 17ms
memory: 3616kb
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 55846 1784 5555646 244554 6736 564546 45545555 6455545 845555 55555544 67456 74456 8464 54577 2376 34557 16476 45474 45744 13745 5555664 558455 54636 6334 5445545 1863 27645 34645 54746 55556455 46345 3746 74546 6633 5455544 738 4776 8666 1455445 555555556 44444 456445 5733 488 5455544 6336 ...
result:
wrong answer 864th lines differ - expected: '5555555555', found: '2147483647'