#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
using namespace std;
using ll = long long;
using ld = long double;
constexpr int SIZE = 1e6+6;
ll dp[SIZE][2];
ll ans = 0;
string As, Bs, Cs;
int A[SIZE];
int B[SIZE];
int C[SIZE];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> As >> Bs >> Cs;
int n = As.size();
for (int i=0; i<n; i++) A[n-i] = As[i]-'0';
for (int i=0; i<n; i++) B[n-i] = Bs[i]-'0';
for (int i=0; i<n; i++) C[n-i] = Cs[i]-'0';
for (int i=1; i<=n; i++){
if (A[i]+B[i] == C[i]) dp[i][0] = dp[i-1][0]+1;
if (A[i]+B[i] == C[i] + 10) dp[i][1] = dp[i-1][0]+1;
if (A[i]+B[i]+1 == C[i]) dp[i][0] = dp[i-1][1];
if (A[i]+B[i]+1 == C[i] + 10) dp[i][1] = dp[i-1][1];
ans += dp[i][0];
}
cout << ans;
return 0;}
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 | #include <bits/stdc++.h> #define F first #define S second #define pii pair<int, int> using namespace std; using ll = long long; using ld = long double; constexpr int SIZE = 1e6+6; ll dp[SIZE][2]; ll ans = 0; string As, Bs, Cs; int A[SIZE]; int B[SIZE]; int C[SIZE]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> As >> Bs >> Cs; int n = As.size(); for (int i=0; i<n; i++) A[n-i] = As[i]-'0'; for (int i=0; i<n; i++) B[n-i] = Bs[i]-'0'; for (int i=0; i<n; i++) C[n-i] = Cs[i]-'0'; for (int i=1; i<=n; i++){ if (A[i]+B[i] == C[i]) dp[i][0] = dp[i-1][0]+1; if (A[i]+B[i] == C[i] + 10) dp[i][1] = dp[i-1][0]+1; if (A[i]+B[i]+1 == C[i]) dp[i][0] = dp[i-1][1]; if (A[i]+B[i]+1 == C[i] + 10) dp[i][1] = dp[i-1][1]; ans += dp[i][0]; } cout << ans; return 0;} |
English