#include <cstdint>
#include <string>
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
string a, b, c; cin >> a >> b >> c;
int64_t cur = 0, res = 0;
for (int i = (int)a.size() - 1; i >= 0; i--) {
int x = a[i] - '0', y = b[i] - '0', z = c[i] - '0';
// cout << i << ": " << x << ' ' << y << ' ' << z << " -------\n";
bool flag = false;
while (i > 0 && x + y > 9) {
if ((x + y) % 10 != z) break;
flag = true;
i--;
x = a[i] - '0' + 1, y = b[i] - '0', z = c[i] - '0';
}
if (flag) {
// cout << "flag\n";
if (x + y == z) {
cur++;
} else {
// cout << i << '\n';
res += cur * (cur + 1) / 2;
cur = 0;
i++;
}
continue;
}
// cout << i << ": " << x << ' ' << y << ' ' << z << '\n';
if (x + y == z) cur++;
else {
res += cur * (cur + 1) / 2;
cur = 0;
}
// cout << cur << ' ' << res << '\n';
}
res += cur * (cur + 1) / 2;
cout << res << '\n';
return 0;
}
/*
908167587018185034
181983446608390336
187098806322030140
1481
2022
3503
58
02
50
666
196
852
037523
040834
978367
*/
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 | #include <cstdint> #include <string> #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string a, b, c; cin >> a >> b >> c; int64_t cur = 0, res = 0; for (int i = (int)a.size() - 1; i >= 0; i--) { int x = a[i] - '0', y = b[i] - '0', z = c[i] - '0'; // cout << i << ": " << x << ' ' << y << ' ' << z << " -------\n"; bool flag = false; while (i > 0 && x + y > 9) { if ((x + y) % 10 != z) break; flag = true; i--; x = a[i] - '0' + 1, y = b[i] - '0', z = c[i] - '0'; } if (flag) { // cout << "flag\n"; if (x + y == z) { cur++; } else { // cout << i << '\n'; res += cur * (cur + 1) / 2; cur = 0; i++; } continue; } // cout << i << ": " << x << ' ' << y << ' ' << z << '\n'; if (x + y == z) cur++; else { res += cur * (cur + 1) / 2; cur = 0; } // cout << cur << ' ' << res << '\n'; } res += cur * (cur + 1) / 2; cout << res << '\n'; return 0; } /* 908167587018185034 181983446608390336 187098806322030140 1481 2022 3503 58 02 50 666 196 852 037523 040834 978367 */ |
English