QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#772225 | #8048. Roman Master | 22016020736# | ML | 0ms | 0kb | C++17 | 2.0kb | 2024-11-22 17:41:05 | 2024-11-22 17:41:05 |
answer
#include<bits/stdc++.h>
using namespace std;
string s;
string ss;
map<string,string>mp;
string dp[40000000];
string minn(string a,string b)
{
if(a.size()==b.size())
{
return a<b?a:b;
}
if(a.size()>b.size()) return b;
else return a;
}
int main()
{
int tt=0;
scanf("%d",&tt);
mp["I"]="1";
mp["II"]="2";
mp["III"]="3";
mp["IV"]="4";
mp["V"]="5";
mp["VI"]="6";
mp["VII"]="7";
mp["VIII"]="8";
while(tt--)
{
int ans=0;
cin>>s;
string kong;
int n=s.size();
for(int i=0;i<n;i++)
{
// printf("111\n");
dp[i].clear();
if(i==0)
{
string sss;
sss=s[i];
// cout<<sss<<"ss "<<endl;
dp[i]=mp[sss];
}
else
{
for(int j=i;j>=max(0,i-4);j--)
{
string curtmp;
for(int k=j;k<=i;k++)
{
if(curtmp.empty()) curtmp=s[k];
else
curtmp+=s[k];
}
//curtmp+=s[j];
if(dp[i].empty())
{
dp[i]=dp[i-1]+mp[curtmp];
// cout<<dp[i-1]<<endl;
}
else if(j==0)
{
if(mp[curtmp]!=kong)
{
// cout<<dp[i]<<" ymp: "<<mp[curtmp]<<endl;
dp[i]=minn(dp[i],mp[curtmp]);
}
}
else
{
if(mp[curtmp]!=kong)
{
dp[i]=minn(dp[i],dp[j-1]+mp[curtmp]);
//cout<<mp[curtmp]<<endl;
}
}
}
}
if(i>=5) dp[i-5].clear();
}
cout<<dp[n-1]<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
3 II IVI VIIIIIV
output:
2 16 634