#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
vector<string> S(3);
for(auto& x : S) cin >> x;
int N = (int)S[0].size();
vector<int> diff(N);
for(int i = 0; i < N; i++){
for(int j = 0; j < 3; j++){
diff[i] += (S[j][i]-'0') * (j >= 2 ? 1 : -1);
}
}
vector<ll> ans(N+1, 1);
ll tot = 0;
for(int i = 0; i < N; i++){
if(diff[i] == 0){
ans[i+1] += ans[i];
} else if(abs(diff[i]) == 1){
int j = i+1;
while(j < N && diff[j] == -9 * diff[i]) j++;
if(j < N && diff[j] == -10 * diff[i]) ans[j+1] += ans[i];
}
tot += (ans[i+1] - 1);
}
cout << tot << '\n';
}
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 | #include <bits/stdc++.h> using namespace std; using ll = int64_t; int main(){ ios_base::sync_with_stdio(false), cin.tie(nullptr); vector<string> S(3); for(auto& x : S) cin >> x; int N = (int)S[0].size(); vector<int> diff(N); for(int i = 0; i < N; i++){ for(int j = 0; j < 3; j++){ diff[i] += (S[j][i]-'0') * (j >= 2 ? 1 : -1); } } vector<ll> ans(N+1, 1); ll tot = 0; for(int i = 0; i < N; i++){ if(diff[i] == 0){ ans[i+1] += ans[i]; } else if(abs(diff[i]) == 1){ int j = i+1; while(j < N && diff[j] == -9 * diff[i]) j++; if(j < N && diff[j] == -10 * diff[i]) ans[j+1] += ans[i]; } tot += (ans[i+1] - 1); } cout << tot << '\n'; } |
English