#include <bits/stdc++.h>
using namespace std;
#define pass (void)0
#define int long long
vector<char> make_abc(string num1, string num2, string num3){
int n=num1.size();
vector<char> abc;
for(int i=0; i<n; i++){
if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'){
abc.push_back('a');
}
else if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'+10){
abc.push_back('b');
}
else if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'-1){
abc.push_back('c');
}
else if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'+9){
abc.push_back('d');
}
else{
abc.push_back('x');
}
}
return abc;
}
vector<char> make_sek(vector<char> abc, int n){
vector<char> sek;
bool cis=false;
for(int i=0; i<n; i++){
if(abc[i]=='a'){
if(cis){
sek.push_back('x');
cis=false;
}
sek.push_back('s');
}
else if(abc[i]=='x'){
cis=false;
sek.push_back('x');
}
else if(abc[i]=='b'){
if(cis){
cis=false;
sek.push_back('s');
}
else{
sek.push_back('x');
}
}
else if(abc[i]=='c'){
if(cis){
sek.push_back('x');
}
cis=true;
}
else if(abc[i]=='d'){
//if(cis==true){
// continue;
//}
if(cis==false){
sek.push_back('x');
}
}
}
return sek;
}
signed main(){
//int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string num1;
string num2;
string num3;
cin >> num1 >> num2 >> num3;
int n=num1.size();
vector<char> abc=make_abc(num1, num2, num3);
vector<char> sek = make_sek(abc, n);
//for(int i=0; i<abc.size(); i++){
// cout << abc[i];
//}
//cout << "\n";
//for(int i=0; i<sek.size(); i++){
// cout << sek[i];
//}
int count=0;
long long res=0;
sek.push_back('x');
for(int i=0; i<sek.size(); i++){
if(sek[i]=='s'){
count++;
}
else{
res += count*(count+1)/2;
count=0;
}
}
cout << res;
}
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #include <bits/stdc++.h> using namespace std; #define pass (void)0 #define int long long vector<char> make_abc(string num1, string num2, string num3){ int n=num1.size(); vector<char> abc; for(int i=0; i<n; i++){ if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'){ abc.push_back('a'); } else if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'+10){ abc.push_back('b'); } else if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'-1){ abc.push_back('c'); } else if((int)(num1[i])-'0' + (int)(num2[i])-'0' == (int)(num3[i])-'0'+9){ abc.push_back('d'); } else{ abc.push_back('x'); } } return abc; } vector<char> make_sek(vector<char> abc, int n){ vector<char> sek; bool cis=false; for(int i=0; i<n; i++){ if(abc[i]=='a'){ if(cis){ sek.push_back('x'); cis=false; } sek.push_back('s'); } else if(abc[i]=='x'){ cis=false; sek.push_back('x'); } else if(abc[i]=='b'){ if(cis){ cis=false; sek.push_back('s'); } else{ sek.push_back('x'); } } else if(abc[i]=='c'){ if(cis){ sek.push_back('x'); } cis=true; } else if(abc[i]=='d'){ //if(cis==true){ // continue; //} if(cis==false){ sek.push_back('x'); } } } return sek; } signed main(){ //int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); string num1; string num2; string num3; cin >> num1 >> num2 >> num3; int n=num1.size(); vector<char> abc=make_abc(num1, num2, num3); vector<char> sek = make_sek(abc, n); //for(int i=0; i<abc.size(); i++){ // cout << abc[i]; //} //cout << "\n"; //for(int i=0; i<sek.size(); i++){ // cout << sek[i]; //} int count=0; long long res=0; sek.push_back('x'); for(int i=0; i<sek.size(); i++){ if(sek[i]=='s'){ count++; } else{ res += count*(count+1)/2; count=0; } } cout << res; } |
English