#pragma GCC optimize ("O3") #include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(int)(b); i++) #define pb push_back #define ALL(x) (x).begin(), (x).end() #define st first #define nd second using namespace std; const int maxN = 20; char in[maxN]; int m; long long res; vector <int> T; void go(int left) { if (left == 0) { long long prod = 1ll; char* p = in; for (int s : T) { swap(p[s], in[m]); int d = atoi(p), fact = 0; swap(p[s], in[m]); FOR(i, 0, 10) if (0 <= d-i and d-i < 10) fact++; if (s == 2 and *p == '0') fact = 0; prod *= fact; p += s; } res += prod; } if (left > 0) T.pb(1), go(left-1), T.back() = 2, go(left-2), T.pop_back(); } void solve() { scanf ("%s", in); m = strlen(in); go(m); printf("%lld\n", res); } int main() { int t; t=1;//scanf ("%d", &t); while (t--) solve(); 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 | #pragma GCC optimize ("O3") #include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(int)(b); i++) #define pb push_back #define ALL(x) (x).begin(), (x).end() #define st first #define nd second using namespace std; const int maxN = 20; char in[maxN]; int m; long long res; vector <int> T; void go(int left) { if (left == 0) { long long prod = 1ll; char* p = in; for (int s : T) { swap(p[s], in[m]); int d = atoi(p), fact = 0; swap(p[s], in[m]); FOR(i, 0, 10) if (0 <= d-i and d-i < 10) fact++; if (s == 2 and *p == '0') fact = 0; prod *= fact; p += s; } res += prod; } if (left > 0) T.pb(1), go(left-1), T.back() = 2, go(left-2), T.pop_back(); } void solve() { scanf ("%s", in); m = strlen(in); go(m); printf("%lld\n", res); } int main() { int t; t=1;//scanf ("%d", &t); while (t--) solve(); return 0; } |