#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
using i128 = __int128;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string a, b, c;
std::cin >> a >> b >> c;
const int n = a.size();
i64 ans = 0;
std::array<int, 2> dp {};
for (int i = 0; i < n; i++) {
const int x = (c[i] - '0') - (a[i] - '0') - (b[i] - '0');
dp[0] += 1;
std::array<int, 2> ndp {};
for (int v = 0; v < 10; v++) {
const int w = v * 10 + x;
if (0 <= w && w < 2) {
ndp[w] += dp[v];
}
}
dp = ndp;
ans += dp[0];
}
std::cout << ans << "\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 | #include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string a, b, c; std::cin >> a >> b >> c; const int n = a.size(); i64 ans = 0; std::array<int, 2> dp {}; for (int i = 0; i < n; i++) { const int x = (c[i] - '0') - (a[i] - '0') - (b[i] - '0'); dp[0] += 1; std::array<int, 2> ndp {}; for (int v = 0; v < 10; v++) { const int w = v * 10 + x; if (0 <= w && w < 2) { ndp[w] += dp[v]; } } dp = ndp; ans += dp[0]; } std::cout << ans << "\n"; return 0; } |
English