#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef short int sint;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<sint, sint> pss;
typedef vector<ll> vll;
typedef vector<int> vint;
typedef vector<sint> vsint;
typedef vector<char> vchar;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<pss> vpss;
typedef vector<ull> vull;
typedef vector<vint> vvint;
typedef vector<vvint> vvvint;
typedef vector<vchar> vvchar;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define rep(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define res(i, m, n) for (int i = (int)(m); i >= (int)(n); --i)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin()+1, (x).end()
int gint(const char& a)
{
return a - '0';
}
int main()
{
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
string a;
string b;
string c;
vint ans, zans;
cin >> a >> b >> c;
int n = a.size();
ans.resize(n+69);
zans.resize(n+69);
int resp = 0;
rep(i, 0, n-1)
{
int sum = gint(a[i]) + gint(b[i]);
if (sum == gint(c[i]))
ans[i] = ans[i-1] + 1;
else if (sum - 10 == gint(c[i]))
{
int it = i-1;
while (it > -1 && gint(a[it]) + gint(b[it]) + 1 == 10 && 0 == gint(c[it]))
--it;
if (it < 0)
ans[i] = 0;
if ((gint(a[it]) + gint(b[it]) + 1) == gint(c[it]))
ans[i] = zans[it] + 1;
if (gint(a[it]) + gint(b[it]) + 1 - 10 == gint(c[it]) && ans[it] > 0)
ans[i] = zans[it] + 1;
}
else
ans[i] = 0;
if (sum < 9)
zans[i] = ans[i];
if (sum > 9)
zans[i] = zans[i-2];
if (sum == 9)
zans[i] = zans[i-1];
resp += ans[i];
}
cout << resp << '\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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef short int sint; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<sint, sint> pss; typedef vector<ll> vll; typedef vector<int> vint; typedef vector<sint> vsint; typedef vector<char> vchar; typedef vector<bool> vbool; typedef vector<vbool> vvbool; typedef vector<vll> vvll; typedef vector<pll> vpll; typedef vector<pii> vpii; typedef vector<pss> vpss; typedef vector<ull> vull; typedef vector<vint> vvint; typedef vector<vvint> vvvint; typedef vector<vchar> vvchar; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; #define rep(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i) #define res(i, m, n) for (int i = (int)(m); i >= (int)(n); --i) #define fi first #define se second #define all(x) (x).begin(), (x).end() #define all1(x) (x).begin()+1, (x).end() int gint(const char& a) { return a - '0'; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); string a; string b; string c; vint ans, zans; cin >> a >> b >> c; int n = a.size(); ans.resize(n+69); zans.resize(n+69); int resp = 0; rep(i, 0, n-1) { int sum = gint(a[i]) + gint(b[i]); if (sum == gint(c[i])) ans[i] = ans[i-1] + 1; else if (sum - 10 == gint(c[i])) { int it = i-1; while (it > -1 && gint(a[it]) + gint(b[it]) + 1 == 10 && 0 == gint(c[it])) --it; if (it < 0) ans[i] = 0; if ((gint(a[it]) + gint(b[it]) + 1) == gint(c[it])) ans[i] = zans[it] + 1; if (gint(a[it]) + gint(b[it]) + 1 - 10 == gint(c[it]) && ans[it] > 0) ans[i] = zans[it] + 1; } else ans[i] = 0; if (sum < 9) zans[i] = ans[i]; if (sum > 9) zans[i] = zans[i-2]; if (sum == 9) zans[i] = zans[i-1]; resp += ans[i]; } cout << resp << '\n'; return 0; } |
English