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 }
保持热爱 不懈努力
不试试看怎么知道会失败呢(划掉)
世上无难事 只要肯放弃(划掉)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步