//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
namespace debug {
template <class c> struct rge { c b, e; };
template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; }
template <class c> char spk(...);
template <class c> auto spk(c *a) -> decltype(cerr << *a, 0);
struct stream {
~stream() { cerr << endl; }
template <class c>
typename enable_if<sizeof spk<c>(0) != 1, stream &>::type operator<<(c i) {
cerr << boolalpha << i;
return *this;
}
template <class c>
typename enable_if<sizeof spk<c>(0) == 1, stream &>::type operator<<(c i) {
return *this << range(begin(i), end(i));
}
template <class a, class b> stream &operator<<(pair<a, b> p) {
return *this << "(" << p.first << ", " << p.second << ")";
}
template <class c> stream &operator<<(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; it++)
*this << ", " + 2 * (it == d.b) << *it;
return *this << "]";
}
stream &_dbg(const string &s, int i, int b) { return *this; }
template <class c, class... cs>
stream &_dbg(const string &s, int i, int b, c arg, cs... args) {
if (i == (int)(s.size()))
return (*this << ": " << arg);
b += (s[i] == '(') + (s[i] == '[') + (s[i] == '{') - (s[i] == ')') -
(s[i] == ']') - (s[i] == '}');
return (s[i] == ',' && b == 0)
? (*this << ": " << arg << " ")._dbg(s, i + 1, b, args...)
: (s[i] == ' ' ? *this : *this << s[i])
._dbg(s, i + 1, b, arg, args...);
}
};
} // namespace debug
#ifdef DEBUG
#define dout debug::stream()
#define dbg(...) ((dout << "line:" << __LINE__ << " >> ")._dbg(#__VA_ARGS__, 0, 0, __VA_ARGS__))
#else
#define dout
#define dbg(...)
#endif
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (b); i >= (a); i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define SZ(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
const int MAXN = 1e6 + 7;
int T[3][MAXN];
int dp[MAXN][2];
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
string A[3];
rep(i, 0, 2) cin >> A[i];
int n = SZ(A[0]);
rep(i, 0, 2) rep(j, 0, n-1) T[i][j] = A[i][j] - '0';
dp[0][0] = T[0][0] + T[1][0] == T[2][0];
dp[0][1] = T[0][0] + T[1][0] + 1 == T[2][0];
dbg(dp[0][0], dp[0][1]);
rep(i, 1, n-1) {
if (T[0][i] + T[1][i] == T[2][i]) {
dp[i][0] = dp[i-1][0] + 1;
}
else if (T[0][i] + T[1][i] + 1 == T[2][i]) {
dp[i][1] = dp[i-1][0] + 1;
}
else if ((T[0][i] + T[1][i]) % 10 == T[2][i]) {
dp[i][0] = dp[i-1][1];
}
else if ((T[0][i] + T[1][i] + 1) % 10 == T[2][i]) {
dp[i][1] = dp[i-1][1];
}
dbg(i, dp[i][0], dp[i][1]);
}
ll ans = 0;
rep(i, 0, n-1) {
ans += dp[i][0];
}
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 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 94 95 96 97 98 99 100 101 102 103 104 105 106 | //#pragma GCC optimize("O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; namespace debug { template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> char spk(...); template <class c> auto spk(c *a) -> decltype(cerr << *a, 0); struct stream { ~stream() { cerr << endl; } template <class c> typename enable_if<sizeof spk<c>(0) != 1, stream &>::type operator<<(c i) { cerr << boolalpha << i; return *this; } template <class c> typename enable_if<sizeof spk<c>(0) == 1, stream &>::type operator<<(c i) { return *this << range(begin(i), end(i)); } template <class a, class b> stream &operator<<(pair<a, b> p) { return *this << "(" << p.first << ", " << p.second << ")"; } template <class c> stream &operator<<(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; it++) *this << ", " + 2 * (it == d.b) << *it; return *this << "]"; } stream &_dbg(const string &s, int i, int b) { return *this; } template <class c, class... cs> stream &_dbg(const string &s, int i, int b, c arg, cs... args) { if (i == (int)(s.size())) return (*this << ": " << arg); b += (s[i] == '(') + (s[i] == '[') + (s[i] == '{') - (s[i] == ')') - (s[i] == ']') - (s[i] == '}'); return (s[i] == ',' && b == 0) ? (*this << ": " << arg << " ")._dbg(s, i + 1, b, args...) : (s[i] == ' ' ? *this : *this << s[i]) ._dbg(s, i + 1, b, arg, args...); } }; } // namespace debug #ifdef DEBUG #define dout debug::stream() #define dbg(...) ((dout << "line:" << __LINE__ << " >> ")._dbg(#__VA_ARGS__, 0, 0, __VA_ARGS__)) #else #define dout #define dbg(...) #endif // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (b); i >= (a); i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define all(a) (a).begin(), (a).end() #define SZ(x) (int)(x).size() #define mp make_pair #define st first #define nd second using ll = long long; using pii = pair<int,int>; using vi = vector<int>; const int MAXN = 1e6 + 7; int T[3][MAXN]; int dp[MAXN][2]; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); string A[3]; rep(i, 0, 2) cin >> A[i]; int n = SZ(A[0]); rep(i, 0, 2) rep(j, 0, n-1) T[i][j] = A[i][j] - '0'; dp[0][0] = T[0][0] + T[1][0] == T[2][0]; dp[0][1] = T[0][0] + T[1][0] + 1 == T[2][0]; dbg(dp[0][0], dp[0][1]); rep(i, 1, n-1) { if (T[0][i] + T[1][i] == T[2][i]) { dp[i][0] = dp[i-1][0] + 1; } else if (T[0][i] + T[1][i] + 1 == T[2][i]) { dp[i][1] = dp[i-1][0] + 1; } else if ((T[0][i] + T[1][i]) % 10 == T[2][i]) { dp[i][0] = dp[i-1][1]; } else if ((T[0][i] + T[1][i] + 1) % 10 == T[2][i]) { dp[i][1] = dp[i-1][1]; } dbg(i, dp[i][0], dp[i][1]); } ll ans = 0; rep(i, 0, n-1) { ans += dp[i][0]; } cout << ans << '\n'; return 0; } |
English