답안 #74688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74688 2018-09-06T14:31:37 Z kjain_1810 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
3 ms 728 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ind(n) scanf("%d", &n)
#define ind2(n, m) scanf("%d%d", &n, &m)
#define ind3(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define inlld(n) scanf("%lld", &n)
#define inlld2(n, m) scanf("%lld%lld", &n, &m)
#define inlld3(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)

using namespace std;

const int N=105;
const int MOD=1e9+7;

typedef long long ll;
typedef long double ld;

ll n, m, digs[22], dp[22][12][12][2];

ll solve(ll dignum, ll last, ll last2, ll isless)
{
    if(dignum<0)
        return 0;
    if(dignum==0)
        return 1;
    if(dp[dignum][last][last2][isless]!=-1)
        return dp[dignum][last][last2][isless];
    if(!isless)
    {
        ll ret=0;
        if(digs[dignum]!=last2 && digs[dignum]!=last)
            ret+=solve(dignum-1, digs[dignum], last, 0);
        for(ll a=digs[dignum]-1; a>=0; a--)
            if(a!=last2 && a!=last)
                ret+=solve(dignum-1, a, last, 1);
        return dp[dignum][last][last2][isless]=ret;
    }
    ll ret=0;
    for(ll a=9; a>=0; a--)
        if(a!=last2 && a!=last)
            ret+=solve(dignum-1, a, last, 1);
    // printf("%lld %lld %lld %lld %lld\n", dignum, last, last2, isless, ret);
    return dp[dignum][last][last2][isless]=ret;
}

ll double_solve(ll here)
{
    if(here==-1)
        return -1;
    ll x=here, a=1;
    for(; x>0; a++)
    {
        digs[a]=x%10;
        x/=10;
    }
    a--;
    // for(ll b=1; b<=a; b++)
    //     printf("%lld ", digs[b]);
    // printf("\n");
    memset(dp, -1, sizeof(dp));
    ll maxi=0;
    for(ll b=digs[a]-1; b>0; b--)
        maxi+=solve(a-1, b, 10, 1);
    maxi+=solve(a-1, digs[a], 10, 0);
    for(ll b=a-1; b>0; b--)
        for(ll c=9; c>0; c--)
            maxi+=solve(b-1, c, 10, 1);
    return maxi;
}

int main()
{
    // while(1)
    // {
    inlld2(n, m);
    ll maxi=double_solve(n-1);
    ll mini=double_solve(m);
    // printf("%lld %lld\n", maxi, mini);
    printf("%lld\n", mini-maxi);
    // }
    return 0;
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define inlld2(n, m) scanf("%lld%lld", &n, &m)
                      ~~~~~^~~~~~~~~~~~~~~~~~~~
numbers.cpp:77:5: note: in expansion of macro 'inlld2'
     inlld2(n, m);
     ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 2 ms 724 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 2 ms 724 KB Output is correct
38 Correct 3 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 2 ms 728 KB Output is correct
45 Correct 3 ms 728 KB Output is correct