#include <bits/stdc++.h>
using namespace std;
#define ll long long
string a;
string b;
string c;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> a;
cin >> b;
cin >> c;
int n = a.length();
ll out=0;
ll dp0=0;
ll dp1=0;
for (int i=n-1; i>=0; i--) {
int s = (a[i]-'0') + (b[i]-'0') - (c[i]-'0');
ll next_dp0=0;
ll next_dp1=0;
if (s == 0) {
next_dp0 = dp0+1;
next_dp1 = 0;
} else if (s == 9) {
next_dp0 = 0;
next_dp1 = dp1;
} else if (s == 10) {
next_dp0 = 0;
next_dp1 = dp0+1;
} else if (s == -1) {
next_dp0 = dp1;
next_dp1 = 0;
} else {
next_dp0 = 0;
next_dp1 = 0;
}
dp0 = next_dp0;
dp1 = next_dp1;
out += dp0;
}
cout << out << "\n";
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 48 49 50 51 52 53 54 | #include <bits/stdc++.h> using namespace std; #define ll long long string a; string b; string c; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> a; cin >> b; cin >> c; int n = a.length(); ll out=0; ll dp0=0; ll dp1=0; for (int i=n-1; i>=0; i--) { int s = (a[i]-'0') + (b[i]-'0') - (c[i]-'0'); ll next_dp0=0; ll next_dp1=0; if (s == 0) { next_dp0 = dp0+1; next_dp1 = 0; } else if (s == 9) { next_dp0 = 0; next_dp1 = dp1; } else if (s == 10) { next_dp0 = 0; next_dp1 = dp0+1; } else if (s == -1) { next_dp0 = dp1; next_dp1 = 0; } else { next_dp0 = 0; next_dp1 = 0; } dp0 = next_dp0; dp1 = next_dp1; out += dp0; } cout << out << "\n"; return 0; } |
English