Submission #621314

# Submission time Handle Problem Language Result Execution time Memory
621314 2022-08-03T17:13:13 Z 353cerega Palindrome-Free Numbers (BOI13_numbers) C++17
72.5 / 100
1 ms 340 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>


using namespace std;


using ll = long long;
using ld = long double;

#define X first
#define Y second

//const ll mod = 1000000007;
const ll mod = 998244353;



ll calc(ll n)
{
    if (n<10) return n+1;
    string s = to_string(n);
    ll A = 1;
    ll N = s.length();
    vector<ll> p8(N);
    p8[0] = 1;
    for (ll i=1;i<N;i++) p8[i] = p8[i-1]*8;
    {
        ll x = 1;
        for (ll j=0;j<N;j++)
        {
            if (j<2) x *= 9;
            else x *= 8;
            A += x;
        }
    }
    p8[N-1] = 9*p8[N-2];
    for (ll i=0;i<N;i++)
    {
        for (ll d=0;d<s[i]-'0';d++)
        {
            if (d==0 and i==0) continue;
            if (i>0 and d==s[i-1]-'0') continue;
            if (i>1 and d==s[i-2]-'0') continue;
            A += p8[N-1-i];
        }
        if (i==N-1)
        {
            ll d = s[i]-'0';
            if (d==0 and i==0) continue;
            if (i>0 and d==s[i-1]-'0') continue;
            if (i>1 and d==s[i-2]-'0') continue;
            A += p8[N-1-i];
        }
        if (i>0 and s[i]==s[i-1]) break;
        if (i>1 and s[i]==s[i-2]) break;
    }
    return A;
}

void solve()
{
    ll L, R;
    cin >> L >> R;
    cout << calc(R)-calc(L-1) << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    ll T;
    T = 1;
    //cin >> T;
    while (T--) solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Correct 0 ms 324 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Incorrect 0 ms 320 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 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 0 ms 328 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Incorrect 1 ms 324 KB Output isn't correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Incorrect 0 ms 212 KB Output isn't correct
11 Correct 0 ms 316 KB Output is correct
12 Incorrect 1 ms 320 KB Output isn't correct
13 Incorrect 0 ms 324 KB Output isn't correct
14 Incorrect 0 ms 320 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 320 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 324 KB Output is correct
26 Correct 0 ms 328 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct