답안 #859486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859486 2023-10-10T08:25:30 Z kh0i Palindrome-Free Numbers (BOI13_numbers) C++17
73.75 / 100
1 ms 604 KB
#include "bits/stdc++.h"
using namespace std;

#define F first
#define S second
#define sz(x) (int)((x).size())

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

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r) {
    assert(l <= r);
    return uniform_int_distribution<ll> (l, r)(rng);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

const int N = 0;
const int LG = __lg(N) + 1;
const int SQ = sqrt(N) + 1;
const ll mod = 1e9 + 7;

ll f[20][12][12][2][2];

ll go(string &s, int cur, int last1, int last2, int tight, int started){
    if(cur >= sz(s))
        return started;

    if(f[cur][last1][last2][tight][started] != -1)
        return f[cur][last1][last2][tight][started];

    ll res = 0;
    int mx = (tight ? s[cur] - '0' : 9);
    for(int nx = 0; nx <= mx; ++nx){
        if(nx == last1 or nx == last2)
            continue;
        int n_tight = (nx == mx ? tight : 0);
        int n_started = (nx > 0 or started);
        res += go(s, cur + 1, last2, nx, n_tight, n_started);
    }
    return f[cur][last1][last2][tight][started] = res;
}

ll calc(string s){
    memset(f, -1, sizeof(f));
    return go(s, 0, 11, 11, 1, 0);
}

void solve(){
    ll l, r;
    cin >> l >> r;
    ll fi = calc(to_string(r));
    if(l > 0)
        fi -= calc(to_string(l - 1));
    else
        ++fi;
    cout << fi;
}


int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    int test = 1;
//    cin >> test;
    for(int i = 1; i <= test; ++i){
//        cout << "Case #" << i << ": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 1 ms 344 KB Output isn't correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 0 ms 464 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Correct 0 ms 344 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Correct 1 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 536 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct