#include "bits/stdc++.h"
#define all(v) (v).begin(), (v).end()
#define st first
#define nd second
#define pb push_back
#define printv(a) { for(auto u : a) cout<<u<<" "; cout<<"\n"; }
#define debug(x) cerr << #x << " = " << x << '\n';
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using si = set<int>;
using mii = map<int,int>;
ll dp[1000005][2];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
string s1,s2,s3;
cin>>s1>>s2>>s3;
int n = s1.size();
ll wyn = 0;
dp[0][0] = 0;
dp[0][1] = 0;
for(int i=1;i<=n;i++){
ll a,b,c;
a = s1[i-1] - '0';
b = s2[i-1] - '0';
c = s3[i-1] - '0';
ll s = a+b, sc = a + b + 1;
if(s % 10 == c){
dp[i][1] = 0;
if(s < 10){
dp[i][0] = dp[i-1][0] + 1;
}else{
dp[i][0] = dp[i-1][1];
}
}else if(sc % 10 == c){
dp[i][0] = 0;
if(sc < 10){
dp[i][1] = dp[i-1][0] + 1;
}else{
dp[i][1] = dp[i-1][1];
}
}else{
dp[i][0] = 0;
dp[i][1] = 0;
}
wyn += dp[i][0];
}
cout<<wyn<<endl;
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 | #include "bits/stdc++.h" #define all(v) (v).begin(), (v).end() #define st first #define nd second #define pb push_back #define printv(a) { for(auto u : a) cout<<u<<" "; cout<<"\n"; } #define debug(x) cerr << #x << " = " << x << '\n'; using namespace std; using ll = long long; using pii = pair<int,int>; using vi = vector<int>; using si = set<int>; using mii = map<int,int>; ll dp[1000005][2]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); string s1,s2,s3; cin>>s1>>s2>>s3; int n = s1.size(); ll wyn = 0; dp[0][0] = 0; dp[0][1] = 0; for(int i=1;i<=n;i++){ ll a,b,c; a = s1[i-1] - '0'; b = s2[i-1] - '0'; c = s3[i-1] - '0'; ll s = a+b, sc = a + b + 1; if(s % 10 == c){ dp[i][1] = 0; if(s < 10){ dp[i][0] = dp[i-1][0] + 1; }else{ dp[i][0] = dp[i-1][1]; } }else if(sc % 10 == c){ dp[i][0] = 0; if(sc < 10){ dp[i][1] = dp[i-1][0] + 1; }else{ dp[i][1] = dp[i-1][1]; } }else{ dp[i][0] = 0; dp[i][1] = 0; } wyn += dp[i][0]; } cout<<wyn<<endl; return 0; } |
English