1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #include <iostream> #include <cstring> #include <algorithm> #include <deque> #include <queue> #include <vector> #include <set> #include <map> #include <cmath> #include <bitset> #include <iterator> #include <random> #include <iomanip>
using namespace std; typedef long long ll; const ll N=static_cast<ll>(2e5)+100; ll res[N],ans[N]; ll n; char s[N];
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>n; for(int i=1;i<=n;++i) { cin>>s[i]; } for(int i=1;i<=n;++i) { res[i]=i*(s[i]-'0')+res[i-1]; } for(int i=1;i<=n;++i) { ans[i]+=res[n+1-i]; ll temp=ans[i]; ans[i]=temp%10; ll cnt=0; while (temp) { ++cnt; temp/=10; ans[i+cnt]+=temp%10; }
} bool isPrint=false; for(int i=N-1;i>=1;--i) { if(ans[i]!=0) isPrint=true; if(isPrint) { cout<<ans[i]; } } }
|