Atcoder Beginner Contest155E(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 }

猜你喜欢

转载自www.cnblogs.com/ldudxy/p/12323984.html