Submission #701064

# Submission time Handle Problem Language Result Execution time Memory
701064 2023-02-20T00:26:53 Z hgmhc Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
1 ms 304 KB
#include <bits/stdc++.h>
using namespace std; using ii = pair<int,int>; using ll = long long;
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
#define siz(x) int((x).size())
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)

ll pw(ll x, ll e) {
    ll r = 1;
    while (e > 0) {
        if (e%2) r *= x;
        e /= 2, x *= x;
    }
    return r;
}

ll calc(vector<int> &v, int n, int k = 0) {
    if (v[k] == v[k+1]) return 0;
    if (n == 2) return 1;
    ll r = 0;
    rep(i,0,v[k+2]-1) if (i != v[k] and i != v[k+1]) {
        r += pw(8,n-3);
    }
    if (v[k] != v[k+2]) r += calc(v,n-1,k+1);
    return r;
}

ll f(ll x) {
    if (x <= 9) return x+1;
    ll c = 10;
    vector<int> v; //digits
    for (int i = 0; i < siz(to_string(x)); ++i) {
        v.push_back(to_string(x)[i]-'0');
    }
    rep(i,1,v[0]-1) rep(j,0,9) if (j != i)
        c += pw(8,siz(v)-2); //first case - (1)
    rep(j,0,v[1]-1) if (j != v[0])
        c += pw(8,siz(v)-2); //first case - (2)
    rep(i,1,siz(v)-2) c += pw(8,siz(v)-2-i)*9*9; //suffix is $...
    return c+calc(v,siz(v)); //calc upper cases
}

int main() {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    printf("%lld", f(b)-f(a-1));
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%lld %lld", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 304 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 300 KB Output is correct
41 Correct 1 ms 296 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct