QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789843 | #8048. Roman Master | roy | WA | 28ms | 3664kb | C++14 | 2.3kb | 2024-11-27 22:13:48 | 2024-11-27 22:13:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int T;
int n;
string s;
pair<int,int> pre[100050];
pair<int,int> dp[100050];
// num highest
void dfs(int x,int v){
if(x!=0){
dfs(pre[x].first,pre[x].second);
}
cout<<v;
}
void Work(){
n=s.size();
s=' '+s;
for(int i=0;i<=n;++i){
pre[i]=make_pair(0x7f7f7f7f,0x7f7f7f7f);
dp[i]=make_pair(0x7f7f7f7f,0x7f7f7f7f);
}
dp[0]=make_pair(0,0);
if(s[1]=='I'){
dp[1]=make_pair(1,1);
pre[1]=make_pair(0,1);
}
if(s[1]=='V'){
dp[1]=make_pair(1,5);
pre[1]=make_pair(0,5);
}
for(int i=2;i<=n;++i){
if(s[i]=='I'){
if(dp[i]>make_pair(dp[i-1].first+1,dp[i-1].second)){
dp[i]=make_pair(dp[i-1].first+1,dp[i-1].second);
pre[i]=make_pair(i-1,1);
}
}
if(s[i]=='V'){
if(dp[i]>make_pair(dp[i-1].first+1,dp[i-1].second)){
dp[i]=make_pair(dp[i-1].first+1,dp[i-1].second);
pre[i]=make_pair(i-1,5);
}
}
if(s[i-1]=='V'&&s[i]=='I'){
if(dp[i]>make_pair(dp[i-2].first+1,(i==2?6:dp[i-2].second))){
dp[i]=make_pair(dp[i-2].first+1,(i==2?6:dp[i-2].second));
pre[i]=make_pair(i-2,6);
}
}
if(s[i-1]=='I'&&s[i]=='V'){
if(dp[i]>make_pair(dp[i-2].first+1,(i==2?4:dp[i-2].second))){
dp[i]=make_pair(dp[i-2].first+1,(i==2?4:dp[i-2].second));
pre[i]=make_pair(i-2,4);
}
}
if(s[i-1]=='I'&&s[i]=='I'){
if(dp[i]>make_pair(dp[i-2].first+1,(i==2?2:dp[i-2].second))){
dp[i]=make_pair(dp[i-2].first+1,(i==2?2:dp[i-2].second));
pre[i]=make_pair(i-2,2);
}
}
if(i>2&&s[i-2]=='I'&&s[i-1]=='I'&&s[i]=='I'){
if(dp[i]>make_pair(dp[i-3].first+1,(i==3?3:dp[i-3].second))){
dp[i]=make_pair(dp[i-3].first+1,(i==3?3:dp[i-3].second));
pre[i]=make_pair(i-3,3);
}
}
if(i>2&&s[i-2]=='V'&&s[i-1]=='I'&&s[i]=='I'){
if(dp[i]>make_pair(dp[i-3].first+1,(i==3?7:dp[i-3].second))){
dp[i]=make_pair(dp[i-3].first+1,(i==3?7:dp[i-3].second));
pre[i]=make_pair(i-3,7);
}
}
if(i>3&&s[i-3]=='V'&&s[i-2]=='I'&&s[i-1]=='I'&&s[i]=='I'){
if(dp[i]>make_pair(dp[i-4].first+1,(i==4?8:dp[i-4].second))){
dp[i]=make_pair(dp[i-4].first+1,(i==4?8:dp[i-4].second));
pre[i]=make_pair(i-4,8);
}
}
}
dfs(pre[n].first,pre[n].second);
cout<<'\n';
return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>T;
for(int i=1;i<=T;++i){
cin>>s;
Work();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
3 II IVI VIIIIIV
output:
2 16 634
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 28ms
memory: 3572kb
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:
5655557 55846 1784 5555756 244565 6826 575656 45655555 6455655 845555 55555665 68556 74456 8475 54577 2376 34557 17576 46585 45865 13855 5555675 558455 54841 6334 5445655 1881 27755 34755 54856 55557555 48255 3856 74656 6831 5455665 738 4776 8666 1456655 555555556 44444 457655 5832 488 5455665 6336 ...
result:
wrong answer 1st lines differ - expected: '5545557', found: '5655557'