답안 #884720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884720 2023-12-08T08:57:53 Z 12345678 Palindrome-Free Numbers (BOI13_numbers) C++17
96.25 / 100
1 ms 600 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 
ll dp[2][19][11][11], a, b;
 
ll query(ll x)
{
    for (int i=0; i<2; i++) for (int j=0; j<19; j++) for (int k=0; k<=10; k++) for (int l=0; l<=10; l++) dp[i][j][k][l]=0;
    ll digit=-1, vl, res=0;
    while (x>0)
    {
        vl=x%10;
        x/=10;
        digit++;
        if (digit==0)
        {
            for (int i=0; i<10; i++) dp[0][digit][10][i]=1;
            for (int i=0; i<=vl; i++) dp[1][digit][10][i]=1; 
        }
        if (digit==1)
        {
            for (int i=0; i<10; i++)
            {
                for (int j=0; j<10; j++)
                {
                    if (i!=j) dp[0][digit][i][j]+=dp[0][digit-1][10][i];
                }
            }
            for (int i=0; i<10; i++)
            {
                for (int j=0; j<vl; j++)
                {
                    if (i!=j) dp[1][digit][i][j]+=dp[0][digit-1][10][i];
                }
            }
            for (int i=0; i<10; i++) if (i!=vl) dp[1][digit][i][vl]+=dp[1][digit-1][10][i];
        }
        if (digit>=2)
        {
            for (int i=0; i<10; i++)
            {
                for (int j=0; j<10; j++)
                {
                    for (int k=0; k<10; k++) if (i!=j&&k!=j) dp[0][digit][i][j]+=dp[0][digit-1][k][i];
                }
            }
            for (int i=0; i<10; i++)
            {
                for (int j=0; j<vl; j++)
                {
                    for (int k=0; k<10; k++) if (i!=j&&k!=j) dp[1][digit][i][j]+=dp[0][digit-1][k][i];
                }
            }
            for (int i=0; i<10; i++) for (int k=0; k<10; k++) if (i!=vl&&vl!=k) dp[1][digit][i][vl]+=dp[1][digit-1][k][i];
        }
        /*
        cout<<"here "<<digit<<'\n';
        for (int i=0; i<=10; i++) 
        {
            for (int j=0; j<=10; j++) cout<<dp[0][digit][i][j]<<' ';
            cout<<'\n';
        }
        cout<<"here2 "<<digit<<'\n';
        for (int i=0; i<=10; i++) 
        {
            for (int j=0; j<=10; j++) cout<<dp[1][digit][i][j]<<' ';
            cout<<'\n';
        }*/
        if (x!=0) for (int i=0; i<=10; i++) for (int j=1; j<=10; j++) res+=dp[0][digit][i][j];
        else for (int i=0; i<=10; i++) for (int j=1; j<=10; j++) res+=dp[1][digit][i][j];
    }
    return res;
}
 
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>a>>b;
    cout<<query(b)-query(a-1)<<'\n';
    //for (int i=51; i<150; i++) cout<<i<<' '<<query(i)<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 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 0 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is 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 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 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 0 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 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 352 KB Output is correct
29 Correct 0 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 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 600 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 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 600 KB Output is correct
45 Correct 0 ms 348 KB Output is correct