/*
alias cpl="g++ -std=c++20 -Wall -Wextra -Wshadow -Wconversion -fmax-errors=3 -O0 -ggdb3 -fsanitize=address,undefined -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -DUNCLE"
alias gdb="ASAN_OPTIONS=detect_leaks=0 gdb -q"
alias gdbb="gdb ./a.out -ex 'start <tes.in'"
alias rnu="./a.out <tes.in >tes.out && cat ./tes.out"
alias q="clear"
*/
#ifndef UNCLE
#pragma GCC optimize("O3,unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,p,q) for(int i=(p); i<=(q); ++i)
#define ROF(i,p,q) for(int i=(p); i>=(q); --i)
#define REP(i,q) for(int i=0; i<(q); ++i)
#define pb push_back
#define as assign
#define rz resize
#define Co const
#define al(X) X.begin(), X.end()
#define ral(X) X.rbegin(), X.rend()
#define sz(X) (int)(X.size())
#define ckmx(a,b) a=max(a,b)
#define ckmn(a,b) a=min(a,b)
#define V vector
typedef long long ll;
typedef long double ld;
typedef mt19937_64 mt;
#ifndef UNCLE
typedef basic_string<bool> vb;
typedef basic_string<int> vi;
typedef basic_string<ll> vl;
#else
typedef V<bool> vb;
typedef V<int> vi;
typedef V<ll> vl;
#endif
constexpr ll INFl=(ll)1e18+14;
constexpr int INFi=1e9+14, MX_N=5e5+14;
int N,M,Q;
void Input(){
string aa,bb,cc;
cin>>aa>>bb>>cc;
N=sz(aa);
vi a(N,-1),b(N,-1),c(N,-1);
REP(i,N) a[i]=aa[i]-'0',b[i]=bb[i]-'0',c[i]=cc[i]-'0';
vi cl(N,0),ad(N+1,0);
int qt=0;
ll rs=0;
REP(i,N){
int g=a[i]+b[i];
if(g>=10) g-=10,ad[i]=1;
if(g==c[i]) cl[i]=1;
else if(g+1==c[i]) cl[i]=2;
else if(g==9&&c[i]==0) cl[i]=2,ad[i]=1;
else cl[i]=3;
}
REP(i,N){
if((i&&cl[i-1]==1&&ad[i]==1)||(i&&cl[i-1]==2&&ad[i]==0)) qt=0;
if(ad[i]==0) ++qt;
if(cl[i]==3) qt=0;
if(cl[i]==1) rs+=qt;
}
cout<<rs<<"\n";
}
void Solv(){
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
Input();
Solv();
}
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 | /* alias cpl="g++ -std=c++20 -Wall -Wextra -Wshadow -Wconversion -fmax-errors=3 -O0 -ggdb3 -fsanitize=address,undefined -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -DUNCLE" alias gdb="ASAN_OPTIONS=detect_leaks=0 gdb -q" alias gdbb="gdb ./a.out -ex 'start <tes.in'" alias rnu="./a.out <tes.in >tes.out && cat ./tes.out" alias q="clear" */ #ifndef UNCLE #pragma GCC optimize("O3,unroll-loops") #endif #include <bits/stdc++.h> using namespace std; #define FOR(i,p,q) for(int i=(p); i<=(q); ++i) #define ROF(i,p,q) for(int i=(p); i>=(q); --i) #define REP(i,q) for(int i=0; i<(q); ++i) #define pb push_back #define as assign #define rz resize #define Co const #define al(X) X.begin(), X.end() #define ral(X) X.rbegin(), X.rend() #define sz(X) (int)(X.size()) #define ckmx(a,b) a=max(a,b) #define ckmn(a,b) a=min(a,b) #define V vector typedef long long ll; typedef long double ld; typedef mt19937_64 mt; #ifndef UNCLE typedef basic_string<bool> vb; typedef basic_string<int> vi; typedef basic_string<ll> vl; #else typedef V<bool> vb; typedef V<int> vi; typedef V<ll> vl; #endif constexpr ll INFl=(ll)1e18+14; constexpr int INFi=1e9+14, MX_N=5e5+14; int N,M,Q; void Input(){ string aa,bb,cc; cin>>aa>>bb>>cc; N=sz(aa); vi a(N,-1),b(N,-1),c(N,-1); REP(i,N) a[i]=aa[i]-'0',b[i]=bb[i]-'0',c[i]=cc[i]-'0'; vi cl(N,0),ad(N+1,0); int qt=0; ll rs=0; REP(i,N){ int g=a[i]+b[i]; if(g>=10) g-=10,ad[i]=1; if(g==c[i]) cl[i]=1; else if(g+1==c[i]) cl[i]=2; else if(g==9&&c[i]==0) cl[i]=2,ad[i]=1; else cl[i]=3; } REP(i,N){ if((i&&cl[i-1]==1&&ad[i]==1)||(i&&cl[i-1]==2&&ad[i]==0)) qt=0; if(ad[i]==0) ++qt; if(cl[i]==3) qt=0; if(cl[i]==1) rs+=qt; } cout<<rs<<"\n"; } void Solv(){ } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); Input(); Solv(); } |
English