Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*#pragma GCC optimize("Ofast")
- #pragma GCC optimize("unroll-loops")*/
- // only when really needed
- /* GNU G++17 7.3.0: No long long for faster code
- GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */
- #include <bits/stdc++.h>
- #define for1(i,a,b) for (int i = a; i <= b; i++)
- #define for2(i,a,b) for (int i = a; i >= b; i--)
- #define int long long
- #define sz(a) (int)a.size()
- #define pii pair<int,int>
- /*
- __builtin_popcountll(x) : Number of 1-bit
- __builtin_ctzll(x) : Number of trailing 0
- */
- #define PI 3.1415926535897932384626433832795
- #define INF 1000000000000000000
- #define MOD 1000000007
- #define MOD2 1000000009
- #define EPS 1e-6
- using namespace std;
- int d[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
- vector<int> v[10] = {{0, 8}, {0, 1, 3, 4, 7, 8, 9}, {2, 8}, {3, 8, 9}, {4, 8, 9}, {5, 6, 8, 9}, {6, 8}, {7, 0, 3, 8, 9}, {8}, {8, 9}};
- int t, ans, cnt;
- string n, s = "";
- bool flag = false;
- void back(int pos) {
- if (pos == sz(n)) {
- if (cnt && s > n) ans++;
- return;
- }
- for (auto f : v[n[pos] - '0']) {
- if (pos > 0 && !flag && f < n[pos] - '0') continue;
- if (pos == 0 && f < n[pos] - '0') continue;
- bool oflag = flag;
- s += char(f + '0');
- if (f != n[pos] - '0') cnt++;
- if (f > n[pos] - '0') flag = true;
- back(pos + 1);
- s.erase(s.end() - 1);
- if (f != n[pos] - '0') cnt--;
- flag = oflag;
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- freopen("CIFRE.inp", "r", stdin);
- freopen("CIFRE.out", "w", stdout);
- cin >> t >> n;
- if (t == 1) {
- for (auto i : n) ans += d[i - '0'];
- cout << ans;
- }
- else {
- back(0);
- cout << ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement