//lubie placki
//dlaczego jestem taki słaby z informatyki :(
//////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define tak cout<<"TAK\n"
#define yes cout<<"YES\n"
#define nie cout<<"NIE\n"
#define no cout<<"NO\n"
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;
#define vec vector
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define linijki ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mapa map<ll,ll>
#define umapa unordered_map<ll,ll>
#define se set<ll>
#define ff first
#define ss second
#define str string
const ll alph = 26;
const ll BIN6 = (1LL << 20);
const ll BIN9 = (1LL << 30);
const ll BIN18 = (1LL << 60);
const ll INF5 = 100000;
const ll INF6 = 1000000;
const ll INF9 = 1000000000;
const ll INF18 = 1000000000000000000;
const ld DINF5 = 1e5L;
const ld DINF6 = 1e6L;
const ld DINF9 = 1e9L;
const ll MOD = 1000000007;
int main() {
linijki;
str a,b,c;
cin>>a>>b>>c;
ll n=sz(a), wyn=0,dpReszt1=0,dpReszt0=0;
for(ll i=n-1;i>=0;--i){
ll reszta0=-1, reszta1=-1;
ll a2=a[i]-'0';
ll b2=b[i]-'0';
ll c2=c[i]-'0';
if((a2+b2+1) % 10 == c2){
reszta1=(a2+b2+1)/10;
}
if((a2+b2) % 10 == c2){
reszta0=(a2+b2)/10;
}
ll nowyWynR0=0, nowyWynR1=0;
if(reszta0>-1){
if(reszta0==0){
nowyWynR0+=1;
}
else{
nowyWynR1+=1;
}
if(dpReszt0>0){
if(reszta0==0){
nowyWynR0+=dpReszt0;
}
else{
nowyWynR1+=dpReszt0;
}
}
}
if(dpReszt1>0 and reszta1>-1){
if(reszta1==0){
nowyWynR0+=dpReszt1;
}
else{
nowyWynR1+=dpReszt1;
}
}
dpReszt1=nowyWynR1;
dpReszt0=nowyWynR0;
wyn+=dpReszt0;
}
cout<<wyn;
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 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 | //lubie placki //dlaczego jestem taki słaby z informatyki :( ////////////////////////////////////////////////// #include <bits/stdc++.h> using namespace std; #define pb push_back #define tak cout<<"TAK\n" #define yes cout<<"YES\n" #define nie cout<<"NIE\n" #define no cout<<"NO\n" using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pdd = pair<ld,ld>; #define vec vector #define all(x) (x).begin(), (x).end() #define sz(x) (x).size() #define linijki ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mapa map<ll,ll> #define umapa unordered_map<ll,ll> #define se set<ll> #define ff first #define ss second #define str string const ll alph = 26; const ll BIN6 = (1LL << 20); const ll BIN9 = (1LL << 30); const ll BIN18 = (1LL << 60); const ll INF5 = 100000; const ll INF6 = 1000000; const ll INF9 = 1000000000; const ll INF18 = 1000000000000000000; const ld DINF5 = 1e5L; const ld DINF6 = 1e6L; const ld DINF9 = 1e9L; const ll MOD = 1000000007; int main() { linijki; str a,b,c; cin>>a>>b>>c; ll n=sz(a), wyn=0,dpReszt1=0,dpReszt0=0; for(ll i=n-1;i>=0;--i){ ll reszta0=-1, reszta1=-1; ll a2=a[i]-'0'; ll b2=b[i]-'0'; ll c2=c[i]-'0'; if((a2+b2+1) % 10 == c2){ reszta1=(a2+b2+1)/10; } if((a2+b2) % 10 == c2){ reszta0=(a2+b2)/10; } ll nowyWynR0=0, nowyWynR1=0; if(reszta0>-1){ if(reszta0==0){ nowyWynR0+=1; } else{ nowyWynR1+=1; } if(dpReszt0>0){ if(reszta0==0){ nowyWynR0+=dpReszt0; } else{ nowyWynR1+=dpReszt0; } } } if(dpReszt1>0 and reszta1>-1){ if(reszta1==0){ nowyWynR0+=dpReszt1; } else{ nowyWynR1+=dpReszt1; } } dpReszt1=nowyWynR1; dpReszt0=nowyWynR0; wyn+=dpReszt0; } cout<<wyn; return 0; } |
English