#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int n;
string a, b, c;
ll ans, dp[2][2];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> a >> b >> c;
n = a.size();
for(int i = n-1; ~i; --i){
dp[0][0]++;
dp[0][1] = dp[1][1] = 0;
int x = a[i] - '0' + b[i] - '0';
int y = x+1;
if(x%10 == (c[i] - '0')) dp[x/10][1] += dp[0][0];
if(y%10 == (c[i] - '0')) dp[y/10][1] += dp[1][0];
dp[0][0] = dp[0][1];
dp[1][0] = dp[1][1];
ans += dp[0][0];
}
cout << ans << '\n';
}
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 | #include "bits/stdc++.h" using namespace std; using ll = long long; int n; string a, b, c; ll ans, dp[2][2]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b >> c; n = a.size(); for(int i = n-1; ~i; --i){ dp[0][0]++; dp[0][1] = dp[1][1] = 0; int x = a[i] - '0' + b[i] - '0'; int y = x+1; if(x%10 == (c[i] - '0')) dp[x/10][1] += dp[0][0]; if(y%10 == (c[i] - '0')) dp[y/10][1] += dp[1][0]; dp[0][0] = dp[0][1]; dp[1][0] = dp[1][1]; ans += dp[0][0]; } cout << ans << '\n'; } |
English