QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788852 | #9672. Roman Numerals | rotcar07 | RE | 8ms | 3848kb | C++23 | 857b | 2024-11-27 18:31:24 | 2024-11-27 18:31:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[18][125][2];
inline void solve(){
ll n;cin>>n;
vector<pair<int,int>> v;
int x;for(int i:{0,1,2,3,4,5,6,7,8,9,1,5,10,50,100,500,1000})cin>>x,v.emplace_back(i,x);
memset(dp,0x3f,sizeof dp);
vector<int> d;while(n) d.push_back(n%10),n/=10;
reverse(d.begin(),d.end());
n=d.size();int inf=dp[0][0][0];
dp[0][0][0]=0;
for(int i=0;i<n;i++)
for(int j=0;j<=120;j++)
for(int k:{0,1})if(dp[i][j][k]<inf){
int r=dp[i][j][k],w=j*10+d[i];
for(auto [x,y]:v)if(x<=w&&w-x<=120){
dp[i+1][w-x][k|!!x]=min(dp[i+1][w-x][k|!!x],r+(!k&&!x?0:y));
}
}
cout<<dp[n][0][1]<<'\n';
}
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3500kb
input:
5 102 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 112 1 5 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 150 1 1 1 1 1 1 1 1 1 1 5 5 5 5 5 5 5 114514 10 5 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1919810 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
2 7 3 6 6
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 7ms
memory: 3848kb
input:
2000 269 2 3 2 2 4 5 5 5 4 5 4 4 2 2 4 1 5 824 2 2 3 5 4 5 4 2 3 5 4 4 4 4 3 4 2 1687 1 2 1 4 4 5 3 5 5 1 4 1 3 1 4 1 5 404 4 4 5 4 5 3 2 3 3 2 3 3 3 3 2 4 5 622 5 1 1 1 2 5 5 2 5 3 2 2 5 4 4 4 1 1576 3 2 1 5 2 4 5 4 5 1 3 5 3 2 1 3 4 211 4 5 4 4 5 2 1 5 2 4 5 2 1 5 2 4 4 1905 1 3 5 4 4 4 5 5 1 2 5 ...
output:
12 10 15 12 7 15 14 9 7 7 10 8 7 8 8 14 7 12 6 6 18 10 9 5 8 8 5 10 6 3 6 11 5 12 5 8 12 12 10 7 8 6 9 12 11 10 6 16 8 3 9 5 9 8 11 10 13 8 10 6 2 10 6 14 11 4 10 9 10 7 8 8 6 7 6 5 8 11 7 10 12 8 9 10 7 6 8 6 7 4 13 4 17 11 11 4 8 13 6 13 8 15 9 5 10 11 11 10 12 11 8 3 8 9 12 11 17 6 13 3 10 3 6 14...
result:
ok 2000 lines
Test #3:
score: 0
Accepted
time: 8ms
memory: 3844kb
input:
2000 672 9999999 9999998 9999996 9999997 10000000 9999999 9999997 10000000 9999996 9999999 9314640 9488995 9532557 9299096 9849641 9257430 9033777 284 9999997 9999996 9999997 9999995 10000000 10000000 10000000 10000000 10000000 10000000 9692000 9904116 9908369 9479290 9509221 9862043 9569004 1825 99...
output:
29999993 29999997 39265704 29538296 39815674 38123541 29999989 29893386 28210567 39939433 29999989 39494370 29999985 29098172 39290220 19033378 29539847 19329537 38815501 29999993 19236316 28961628 38016891 39702526 9479788 19999990 29492874 28522935 39147290 29687093 9179737 39417973 28732959 29147...
result:
ok 2000 lines
Test #4:
score: 0
Accepted
time: 8ms
memory: 3568kb
input:
2000 997 9864608 9140848 9683324 9679700 9767541 9010880 9866039 9108910 9286192 9580767 9999995 10000000 9999999 9999999 9999996 10000000 10000000 206 9717380 9328349 9621557 9939866 9984405 9582976 9522182 9152140 9150277 9568937 9999999 9999999 9999997 9999995 9999998 10000000 9999997 1754 993391...
output:
28270444 28850528 38432383 28945128 38754944 38799627 28654249 37358082 37234376 28173261 29095501 27980514 19464338 28854566 29038010 28133002 29330665 18439360 28777758 37595386 38299390 28482046 37708661 37962133 28502951 19054192 28906209 27051210 19440760 28557895 19760817 28451453 37750541 194...
result:
ok 2000 lines
Test #5:
score: 0
Accepted
time: 8ms
memory: 3616kb
input:
2000 1986 6562476 373300 853204 3955722 7465376 3471513 6782061 6770363 4815249 9440262 3098544 9516481 4913998 3157523 653990 4901757 7799353 672 2247049 2520745 2441923 863302 6828648 8017897 8956381 8318080 6976098 8610282 9592455 8140933 7702622 5575556 6903409 3405061 6674934 1004 1101154 82176...
output:
21410872 19716384 1632537 14894598 11321250 24316204 10730439 20711612 19463846 22111280 11092104 6859939 26853873 11503218 16007380 26548673 15400127 15459622 13057083 19203050 20023355 16649034 6639422 16334338 9670434 10494185 12577327 11163113 31335647 15346594 7016272 5165733 18683249 12439558 ...
result:
ok 2000 lines
Test #6:
score: -100
Runtime Error
input:
2000 999999999999998939 9999995 9999997 9999995 9999996 10000000 9999999 9999995 9999996 9999999 9999998 9999999 9999997 9999995 9999996 9999995 9999997 9999999 999999999999998523 9999996 9999998 9999999 9999996 10000000 10000000 9999999 10000000 10000000 9999997 9999997 9999996 10000000 9999996 100...