Atcoder Beginner Contest 155E(DP)

 

复制代码
 1 #definde HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 char s[1000007];
 5 int main(){
 6     ios::sync_with_stdio(false);
 7     cin.tie(NULL);
 8     cout.tie(NULL);
 9     cin>>s+1;
10     int n=strlen(s+1);
11     int ans=0;
12     for(int i=n;i;--i){
13         if(s[i]<'5'||s[i]=='5'&&s[i-1]<'5')
14             ans+=s[i]-'0';
15         else{
16             ans+=10-(s[i]-'0');
17             ++s[i-1];
18         }
19     }
20     if(s[0])
21         ++ans;
22     cout<<ans;
23     return 0;
24 }
复制代码

 

posted @   sewage  阅读(196)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示