답안 #74673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74673 2018-09-06T11:10:52 Z kjain_1810 Palindrome-Free Numbers (BOI13_numbers) C++17
40.8333 / 100
3 ms 748 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+9;

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, last, digs[dignum], 0);
        for(int a=digs[dignum]-1; a>=0; a--)
            if(a!=last2 && a!=last)
                ret+=solve(dignum-1, last, a, 1);
        return dp[dignum][last][last2][isless]=ret;
    }
    ll ret=0;
    for(int a=9; a>=0; a--)
        if(a!=last2 && a!=last)
            ret+=solve(dignum-1, last, a, 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)
{
    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, 11, 1);
    maxi+=solve(a-1, digs[a], 11, 0);
    for(int b=a-1; b>0; b--)
        for(int c=9; c>0; c--)
            maxi+=solve(b-1, c, 11, 1);
    return maxi;
}

int main()
{
    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:73:5: note: in expansion of macro 'inlld2'
     inlld2(n, m);
     ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 452 KB Output isn't correct
4 Incorrect 2 ms 592 KB Output isn't correct
5 Correct 2 ms 656 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 2 ms 656 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 2 ms 656 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 2 ms 656 KB Output is correct
14 Incorrect 2 ms 656 KB Output isn't correct
15 Correct 2 ms 656 KB Output is correct
16 Incorrect 3 ms 656 KB Output isn't correct
17 Correct 2 ms 656 KB Output is correct
18 Incorrect 2 ms 656 KB Output isn't correct
19 Incorrect 2 ms 656 KB Output isn't correct
20 Correct 2 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 656 KB Output is correct
2 Incorrect 2 ms 656 KB Output isn't correct
3 Incorrect 2 ms 656 KB Output isn't correct
4 Incorrect 2 ms 656 KB Output isn't correct
5 Incorrect 2 ms 656 KB Output isn't correct
6 Incorrect 2 ms 656 KB Output isn't correct
7 Incorrect 2 ms 656 KB Output isn't correct
8 Correct 2 ms 656 KB Output is correct
9 Incorrect 2 ms 656 KB Output isn't correct
10 Incorrect 2 ms 656 KB Output isn't correct
11 Correct 2 ms 656 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Incorrect 2 ms 748 KB Output isn't correct
14 Incorrect 2 ms 748 KB Output isn't correct
15 Correct 2 ms 748 KB Output is correct
16 Incorrect 2 ms 748 KB Output isn't correct
17 Correct 2 ms 748 KB Output is correct
18 Incorrect 2 ms 748 KB Output isn't correct
19 Correct 2 ms 748 KB Output is correct
20 Incorrect 2 ms 748 KB Output isn't correct
21 Incorrect 2 ms 748 KB Output isn't correct
22 Incorrect 2 ms 748 KB Output isn't correct
23 Incorrect 2 ms 748 KB Output isn't correct
24 Correct 2 ms 748 KB Output is correct
25 Incorrect 2 ms 748 KB Output isn't correct
26 Incorrect 3 ms 748 KB Output isn't correct
27 Incorrect 2 ms 748 KB Output isn't correct
28 Incorrect 3 ms 748 KB Output isn't correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Incorrect 2 ms 748 KB Output isn't correct
32 Correct 2 ms 748 KB Output is correct
33 Incorrect 2 ms 748 KB Output isn't correct
34 Correct 3 ms 748 KB Output is correct
35 Incorrect 2 ms 748 KB Output isn't correct
36 Incorrect 2 ms 748 KB Output isn't correct
37 Incorrect 2 ms 748 KB Output isn't correct
38 Incorrect 2 ms 748 KB Output isn't correct
39 Incorrect 2 ms 748 KB Output isn't correct
40 Correct 2 ms 748 KB Output is correct
41 Incorrect 2 ms 748 KB Output isn't correct
42 Correct 2 ms 748 KB Output is correct
43 Incorrect 2 ms 748 KB Output isn't correct
44 Incorrect 2 ms 748 KB Output isn't correct
45 Incorrect 2 ms 748 KB Output isn't correct