#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define irep(i,a,b) for(int i = a; i >= b; i--)
typedef long long ll;
typedef long double ld;
//typedef __int128 int128;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
const int max_n = 1e6+7;
ll a[max_n];
ll b[max_n];
ll c[max_n];
ll dp[max_n][2];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s1,s2,s3;
cin >> s1 >> s2 >> s3;
ll n = s1.length();
rep(i,1,n){
a[i] = s1[i-1]-'0';
b[i] = s2[i-1]-'0';
c[i] = s3[i-1]-'0';
}
irep(i,n,1){
//0 - bez carry
//1 - carry 1 do nastepnego!!!
//2 casy!
//cout << "\ni: " << i << '\n';
ll v = a[i]+b[i]+1;
if(v%10 == c[i]){
//cout << "dziala+1\n";
if(v >= 10) dp[i][1] += dp[i+1][1];
else dp[i][0] += dp[i+1][1];
}
v--;
if(v%10 == c[i]){
//cout << "dziala+0\n";
if(v >= 10) dp[i][1] += dp[i+1][0]+1;
else dp[i][0] += dp[i+1][0]+1;
}
}
ll ans = 0;
rep(i,1,n) ans += dp[i][0]; //bez carry 1!!!
cout << ans;
return 0;
}
//g++ -O3 -static -Wall .cpp -std=c++17
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 <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back #define rep(i,a,b) for(int i = a; i <= b; i++) #define irep(i,a,b) for(int i = a; i >= b; i--) typedef long long ll; typedef long double ld; //typedef __int128 int128; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pi; typedef pair<double,double> pd; typedef pair<ll,ll> pl; const int max_n = 1e6+7; ll a[max_n]; ll b[max_n]; ll c[max_n]; ll dp[max_n][2]; int main(){ ios::sync_with_stdio(0); cin.tie(0); string s1,s2,s3; cin >> s1 >> s2 >> s3; ll n = s1.length(); rep(i,1,n){ a[i] = s1[i-1]-'0'; b[i] = s2[i-1]-'0'; c[i] = s3[i-1]-'0'; } irep(i,n,1){ //0 - bez carry //1 - carry 1 do nastepnego!!! //2 casy! //cout << "\ni: " << i << '\n'; ll v = a[i]+b[i]+1; if(v%10 == c[i]){ //cout << "dziala+1\n"; if(v >= 10) dp[i][1] += dp[i+1][1]; else dp[i][0] += dp[i+1][1]; } v--; if(v%10 == c[i]){ //cout << "dziala+0\n"; if(v >= 10) dp[i][1] += dp[i+1][0]+1; else dp[i][0] += dp[i+1][0]+1; } } ll ans = 0; rep(i,1,n) ans += dp[i][0]; //bez carry 1!!! cout << ans; return 0; } //g++ -O3 -static -Wall .cpp -std=c++17 |
English