답안 #373940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373940 2021-03-06T08:16:19 Z nguyen31hoang08minh2003 Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
2 ms 512 KB
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <math.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <bitset>
#include <iterator>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <map>
#include <ctime>
#define fore(i, a, b) for(ll i = (a), _b = (b); i < (_b); i++)
#define fort(i, a, b) for(ll i = (a), _b = (b); i <= (_b); i++)
#define ford(i, a, b) for(ll i = (a), _b = (b); i >= (_b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
using namespace std;

template<class A,class B> bool mini(A &a,const B b){return a > b ? (a = b, 1) : 0; }
template<class A,class B> bool maxi(A &a,const B b){return a < b ? (a = b, 1) : 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

ll n, a, b, T, dp[25][2][12][12][2],
   vis[25][2][12][12][2];
string t;

ll DP(ll i, bool f, ll x, ll y, bool st) {
    if (i >= n)
        return 1;
    #define v i][f][x][y][st
    if (vis[v] != T) {
        vis[v] = T;
        dp[v] = 0;
        const int d = f ? 9 : (t[i] - '0');
        fort(j, 0, d)
            if (!j) {
                if (st)
                    dp[v] += DP(i + 1, f || (j < d), 10, 10, true);
                else if (x != j && y != j)
                    dp[v] += DP(i + 1, f || (j < d), y, j, false);
            } else {
                if (x != j && y != j)
                    dp[v] += DP(i + 1, f || (j < d), y, j, false);
            }
    }
    return dp[v];
    #undef v
}

ll calc(ll x) {
    stringstream ss;
    ss << x;
    ss >> t;
    ++T;
    n = sz(t);
    return DP(0, false, 10, 10, false);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b;
    if (!a)
        cout << calc(b) << '\n';
    else
        cout << calc(b) - calc(a - 1) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Incorrect 1 ms 364 KB Output isn't correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Incorrect 1 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Incorrect 1 ms 364 KB Output isn't correct
11 Correct 1 ms 364 KB Output is correct
12 Incorrect 1 ms 364 KB Output isn't correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Incorrect 1 ms 364 KB Output isn't correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 440 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 1 ms 492 KB Output is correct