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
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string a,b,c;
cin>>a>>b>>c;
int i,d1,d2,d3,n0,n1;
long long t=0;
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
reverse(c.begin(),c.end());
vector<long long>ile0(a.size(),0),ile1(a.size(),0);
   for(i=0;i<a.size();++i){
   d1=a[i]-48;d2=b[i]-48;d3=c[i]-48;
      if((d1+d2)%10==d3){
      n0=(d1+d2>=10)?1:0;
      long long s=1+(i>0?ile0[i-1]:0);
      if(n0==0){ile0[i]=s;t+=s;}
    else ile1[i]=s;}
    if(i>0&&(d1+d2+1)%10==d3){
       n1=(d1+d2+1>=10)?1:0;
       long long s=ile1[i-1];
       if(n1==0){ile0[i]+=s;t+=s;}
       else ile1[i]+=s;}}
        cout<<t;
return 0;
}