#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string A,B,SUM;
cin >> A >> B >> SUM;
int n = A.size();
ll dp0 = 0, dp1 = 0, res = 0;
for(int i = n - 1; i >= 0; i--){
int a = A[i] - '0';
int b = B[i] - '0';
int c = SUM[i] - '0';
ll temp0 = 0, temp1 = 0;
int s = a + b;
if(s % 10 == c){
if(s < 10) temp0++;
else temp1++;
}
if(dp0 > 0){
if(s % 10 == c){
if(s < 10) temp0 += dp0;
else temp1 += dp0;
}
}
int s1 = a + b + 1;
if(dp1 > 0){
if(s1 % 10 == c){
if(s1 < 10) temp0 += dp1;
else temp1 += dp1;
}
}
dp0 = temp0;
dp1 = temp1;
res += dp0;
}
cout << res;
}
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 | #include<bits/stdc++.h> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string A,B,SUM; cin >> A >> B >> SUM; int n = A.size(); ll dp0 = 0, dp1 = 0, res = 0; for(int i = n - 1; i >= 0; i--){ int a = A[i] - '0'; int b = B[i] - '0'; int c = SUM[i] - '0'; ll temp0 = 0, temp1 = 0; int s = a + b; if(s % 10 == c){ if(s < 10) temp0++; else temp1++; } if(dp0 > 0){ if(s % 10 == c){ if(s < 10) temp0 += dp0; else temp1 += dp0; } } int s1 = a + b + 1; if(dp1 > 0){ if(s1 % 10 == c){ if(s1 < 10) temp0 += dp1; else temp1 += dp1; } } dp0 = temp0; dp1 = temp1; res += dp0; } cout << res; } |
English