//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
using i128=__int128_t;
void die(string S){puts(S.c_str());exit(0);}
string s,t,u;
int ban[1001000],n;
int cr[1001000],nd[1001000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>s>>t>>u;
n=sz(s);
for(int i=0;i<n;i++)
{
ban[i]=1;
for(int a=0;a<2;a++)
for(int b=0;b<2;b++)
if((s[i]^48)+(t[i]^48)+a==b*10+(u[i]^48))
{
cr[i]=b;
nd[i]=a;
ban[i]=0;
}
}
ll ans=0;
int last=-1,tot=0;
for(int j=0;j<n;j++)
{
if(j&&cr[j]!=nd[j-1])
{
last=j-1;
tot=0;
}
if(!cr[j]) tot++;
if(ban[j])
{
last=j;
tot=0;
}
if(!nd[j])
ans+=tot;
}
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 | //Author: Kevin #include<bits/stdc++.h> //#pragma GCC optimize("O2") using namespace std; #define pb emplace_back #define mp make_pair #define ALL(x) (x).begin(),(x).end() #define rALL(x) (x).rbegin(),(x).rend() #define srt(x) sort(ALL(x)) #define rev(x) reverse(ALL(x)) #define rsrt(x) sort(rALL(x)) #define sz(x) (int)(x.size()) #define inf 0x3f3f3f3f #define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin()) #define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin()) #define uni(v) v.resize(unique(ALL(v))-v.begin()) using ll=long long; using ull=unsigned long long; using pii=pair<int,int>; using i128=__int128_t; void die(string S){puts(S.c_str());exit(0);} string s,t,u; int ban[1001000],n; int cr[1001000],nd[1001000]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>s>>t>>u; n=sz(s); for(int i=0;i<n;i++) { ban[i]=1; for(int a=0;a<2;a++) for(int b=0;b<2;b++) if((s[i]^48)+(t[i]^48)+a==b*10+(u[i]^48)) { cr[i]=b; nd[i]=a; ban[i]=0; } } ll ans=0; int last=-1,tot=0; for(int j=0;j<n;j++) { if(j&&cr[j]!=nd[j-1]) { last=j-1; tot=0; } if(!cr[j]) tot++; if(ban[j]) { last=j; tot=0; } if(!nd[j]) ans+=tot; } cout<<ans<<'\n'; return 0; } |
English