#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s1,s2,s3;
cin >> s1 >> s2 >> s3;
int n = s1.size();
vector <ll> dpBez(n+1), dpPrzeniesienie(n+1);
ll wyn = 0;
for (int i = n-1; i >= 0; i--) {
int ile = s1[i]+s2[i]-s3[i]-'0';
if (ile == 10) dpPrzeniesienie[i] = dpBez[i+1]+1;
if (ile == 0) dpBez[i] = dpBez[i+1]+1;
if (ile == -1) dpBez[i] = dpPrzeniesienie[i+1];
if (ile == 9) dpPrzeniesienie[i] = dpPrzeniesienie[i+1];
wyn+=dpBez[i];
}
cout << wyn << "\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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main () { ios_base::sync_with_stdio(0); cin.tie(0); string s1,s2,s3; cin >> s1 >> s2 >> s3; int n = s1.size(); vector <ll> dpBez(n+1), dpPrzeniesienie(n+1); ll wyn = 0; for (int i = n-1; i >= 0; i--) { int ile = s1[i]+s2[i]-s3[i]-'0'; if (ile == 10) dpPrzeniesienie[i] = dpBez[i+1]+1; if (ile == 0) dpBez[i] = dpBez[i+1]+1; if (ile == -1) dpBez[i] = dpPrzeniesienie[i+1]; if (ile == 9) dpPrzeniesienie[i] = dpPrzeniesienie[i+1]; wyn+=dpBez[i]; } cout << wyn << "\n"; return 0; } |
English