#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false
const int MAXN = 1000 * 1000 + 17;
ll dp[MAXN][2];
string a, b, s;
int main () {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> a >> b >> s;
int n = int(a.size());
ll wyn = 0;
for (int i = n - 1; i >= 0; i --) {
for (int j = 0; j <= 1; j ++) {
int x = int(a[i]) - int('0') + int(b[i]) - int('0') + j;
if (x % 10 != (int(s[i]) - int('0'))) {
continue;
}
if (x >= 10) {
dp[i][1] += dp[i + 1][j];
} else {
dp[i][0] += dp[i + 1][j];
}
}
int x = int(a[i]) - int('0') + int(b[i]) - int('0');
if (x % 10 == (int(s[i]) - int('0'))) {
if (x >= 10) {
dp[i][1] ++;
} else {
dp[i][0] ++;
}
}
wyn += dp[i][0];
}
cout << wyn << "\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 55 56 57 58 59 60 61 | #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define st first #define nd second #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define debug false const int MAXN = 1000 * 1000 + 17; ll dp[MAXN][2]; string a, b, s; int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b >> s; int n = int(a.size()); ll wyn = 0; for (int i = n - 1; i >= 0; i --) { for (int j = 0; j <= 1; j ++) { int x = int(a[i]) - int('0') + int(b[i]) - int('0') + j; if (x % 10 != (int(s[i]) - int('0'))) { continue; } if (x >= 10) { dp[i][1] += dp[i + 1][j]; } else { dp[i][0] += dp[i + 1][j]; } } int x = int(a[i]) - int('0') + int(b[i]) - int('0'); if (x % 10 == (int(s[i]) - int('0'))) { if (x >= 10) { dp[i][1] ++; } else { dp[i][0] ++; } } wyn += dp[i][0]; } cout << wyn << "\n"; return 0; } |
English