QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572436 | #8048. Roman Master | ggggggg | WA | 197ms | 3804kb | C++14 | 1007b | 2024-09-18 14:30:54 | 2024-09-18 14:30:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,g[N];
string s;
map<string,int> mp;
pair<int,int> dp[N];
int cmin(pair<int,int>&x,pair<int,int> y){
if(x>y) return x=y,1;
return 0;
}
void solve(){
cin>>s,n=s.length();
dp[0]={0,0};
for(int i=1;i<=n;i++) dp[i]={1e9,0};
for(int i=1;i<=n;i++){
for(int j=max(0,i-4);j<i;j++){
if(mp.count(s.substr(j,i-j))){
if(cmin(dp[i],make_pair(dp[j].first+1,dp[j].second)))
g[i]=j;
}
}
dp[i].second=mp[s.substr(g[i],i-g[i])];
}
vector<int> v;
int t=n;
while(t!=0) v.push_back(mp[s.substr(g[t],t-g[t])]),t=g[t];
for(int i=(int)(v.size())-1;i>=0;i--) printf("%d",v[i]);
puts("");
}
int main(){
mp["I"]=1;
mp["II"]=2;
mp["III"]=3;
mp["IV"]=4;
mp["V"]=5;
mp["VI"]=6;
mp["VII"]=7;
mp["VIII"]=8;
int T;
scanf("%d",&T);
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
3 II IVI VIIIIIV
output:
2 16 634
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 197ms
memory: 3804kb
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 79th lines differ - expected: '56366', found: '58441'