/* 2026
* Maciej Szeptuch
*/
#include <cstdio>
const int MAX_DIGITS = 1048576;
char A[MAX_DIGITS];
char B[MAX_DIGITS];
char C[MAX_DIGITS];
int parts;
int length;
long long result;
int main(void)
{
scanf("%s%n %s %s\n", A, &length, B, C);
for(int p = length - 1; p >= 0; --p)
{
if(A[p] - '0' + B[p] - '0' == C[p] - '0')
{
++parts;
continue;
}
if(A[p] - '0' + B[p] - '0' == 10 + C[p] - '0')
{
while(p > 0 && A[p - 1] - '0' + B[p - 1] - '0' + 1 == 10 + C[p - 1] - '0')
--p;
if(p > 0 && A[p - 1] - '0' + B[p - 1] - '0' + 1 == C[p - 1] - '0')
{
--p;
++parts;
continue;
}
}
result += 1LL * parts * (parts + 1) / 2;
parts = 0;
}
printf("%lld\n", result + 1LL * parts * (parts + 1) / 2);
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 | /* 2026 * Maciej Szeptuch */ #include <cstdio> const int MAX_DIGITS = 1048576; char A[MAX_DIGITS]; char B[MAX_DIGITS]; char C[MAX_DIGITS]; int parts; int length; long long result; int main(void) { scanf("%s%n %s %s\n", A, &length, B, C); for(int p = length - 1; p >= 0; --p) { if(A[p] - '0' + B[p] - '0' == C[p] - '0') { ++parts; continue; } if(A[p] - '0' + B[p] - '0' == 10 + C[p] - '0') { while(p > 0 && A[p - 1] - '0' + B[p - 1] - '0' + 1 == 10 + C[p - 1] - '0') --p; if(p > 0 && A[p - 1] - '0' + B[p - 1] - '0' + 1 == C[p - 1] - '0') { --p; ++parts; continue; } } result += 1LL * parts * (parts + 1) / 2; parts = 0; } printf("%lld\n", result + 1LL * parts * (parts + 1) / 2); return 0; } |
English