#include <bits/stdc++.h>
using namespace std;
#define ll long long
string a, b, c;
int n;
ll ans;
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> a >> b >> c;
n = a.size();
ans = 0;
ll end0 = 0, end1 = 0;
for(int i = 0; i < n; i++){
int x = a[i] - '0';
int y = b[i] - '0';
int z = c[i] - '0';
ll start0 = end0 + 1;//ile poczatkow przedzialow
ll start1 = end1;
ll nxt0 = 0;//ile w nastepnym poczatkow
ll nxt1 = 0;
if(start0 > 0){
int nxt = z - x - y;//przenosimy 0
if(nxt == 0) nxt0 += start0;
else if(nxt == 1) nxt1 += start0;
}
if(start1 > 0){
int nxt = 10 + z - x - y;//przenosimy 1
if(nxt == 0) nxt0 += start1;
else if(nxt == 1) nxt1 += start1;
}
end0 = nxt0;
end1 = nxt1;
ans += end0;
}
cout << ans;
}
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 | #include <bits/stdc++.h> using namespace std; #define ll long long string a, b, c; int n; ll ans; int main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> a >> b >> c; n = a.size(); ans = 0; ll end0 = 0, end1 = 0; for(int i = 0; i < n; i++){ int x = a[i] - '0'; int y = b[i] - '0'; int z = c[i] - '0'; ll start0 = end0 + 1;//ile poczatkow przedzialow ll start1 = end1; ll nxt0 = 0;//ile w nastepnym poczatkow ll nxt1 = 0; if(start0 > 0){ int nxt = z - x - y;//przenosimy 0 if(nxt == 0) nxt0 += start0; else if(nxt == 1) nxt1 += start0; } if(start1 > 0){ int nxt = 10 + z - x - y;//przenosimy 1 if(nxt == 0) nxt0 += start1; else if(nxt == 1) nxt1 += start1; } end0 = nxt0; end1 = nxt1; ans += end0; } cout << ans; } |
English