Submission #31369

# Submission time Handle Problem Language Result Execution time Memory
31369 2017-08-20T12:02:46 Z imaxblue Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
0 ms 2052 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0LL, sizeof x)
#define rng() (rand() >> 3)*rand()

ll x, y, d, p;
ll dp[11][11][20][2];
ll solve(ll X){
    if (X<0) return 0;
    if (X==0) return 1;
    drain(dp);
    dp[10][10][0][0]=1;
    ll ans=0;
    for(int l=0; X>0; ++l){
        p=l+1;
        d=X%10; X/=10;
        fox(l2, 10){
            fox(l3, 11){
                if (l3==l2) continue;
                fox(l4, 11){
                    if (l4==l2) continue;
                    if (l2<d)
                        dp[l2][l3][l+1][0]+=dp[l3][l4][l][0]+dp[l3][l4][l][1];
                    if (l2>d)
                        dp[l2][l3][l+1][1]+=dp[l3][l4][l][0]+dp[l3][l4][l][1];
                    if (l2==d){
                        dp[l2][l3][l+1][1]+=dp[l3][l4][l][1];
                        dp[l2][l3][l+1][0]+=dp[l3][l4][l][0];
                    }
                }
            }
        }
        for (int l2=(l!=0); l2<10; ++l2){
            fox(l3, 11){
                ans+=dp[l2][l3][l+1][0];
                if (X>0) ans+=dp[l2][l3][l+1][1];
            }
        }
        //cout << ans << endl;
    }
    //cout << ans << endl;
    return ans;
}
int main(){
    cin >> x >> y;
    cout << solve(y)-solve(x-1) << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2052 KB Output is correct
2 Correct 0 ms 2052 KB Output is correct
3 Correct 0 ms 2052 KB Output is correct
4 Correct 0 ms 2052 KB Output is correct
5 Correct 0 ms 2052 KB Output is correct
6 Correct 0 ms 2052 KB Output is correct
7 Correct 0 ms 2052 KB Output is correct
8 Correct 0 ms 2052 KB Output is correct
9 Correct 0 ms 2052 KB Output is correct
10 Correct 0 ms 2052 KB Output is correct
11 Correct 0 ms 2052 KB Output is correct
12 Correct 0 ms 2052 KB Output is correct
13 Correct 0 ms 2052 KB Output is correct
14 Correct 0 ms 2052 KB Output is correct
15 Correct 0 ms 2052 KB Output is correct
16 Correct 0 ms 2052 KB Output is correct
17 Correct 0 ms 2052 KB Output is correct
18 Correct 0 ms 2052 KB Output is correct
19 Correct 0 ms 2052 KB Output is correct
20 Correct 0 ms 2052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2052 KB Output is correct
2 Correct 0 ms 2052 KB Output is correct
3 Correct 0 ms 2052 KB Output is correct
4 Correct 0 ms 2052 KB Output is correct
5 Correct 0 ms 2052 KB Output is correct
6 Correct 0 ms 2052 KB Output is correct
7 Correct 0 ms 2052 KB Output is correct
8 Correct 0 ms 2052 KB Output is correct
9 Correct 0 ms 2052 KB Output is correct
10 Correct 0 ms 2052 KB Output is correct
11 Correct 0 ms 2052 KB Output is correct
12 Correct 0 ms 2052 KB Output is correct
13 Correct 0 ms 2052 KB Output is correct
14 Correct 0 ms 2052 KB Output is correct
15 Correct 0 ms 2052 KB Output is correct
16 Correct 0 ms 2052 KB Output is correct
17 Correct 0 ms 2052 KB Output is correct
18 Correct 0 ms 2052 KB Output is correct
19 Correct 0 ms 2052 KB Output is correct
20 Correct 0 ms 2052 KB Output is correct
21 Correct 0 ms 2052 KB Output is correct
22 Correct 0 ms 2052 KB Output is correct
23 Correct 0 ms 2052 KB Output is correct
24 Correct 0 ms 2052 KB Output is correct
25 Correct 0 ms 2052 KB Output is correct
26 Correct 0 ms 2052 KB Output is correct
27 Correct 0 ms 2052 KB Output is correct
28 Correct 0 ms 2052 KB Output is correct
29 Correct 0 ms 2052 KB Output is correct
30 Correct 0 ms 2052 KB Output is correct
31 Correct 0 ms 2052 KB Output is correct
32 Correct 0 ms 2052 KB Output is correct
33 Correct 0 ms 2052 KB Output is correct
34 Correct 0 ms 2052 KB Output is correct
35 Correct 0 ms 2052 KB Output is correct
36 Correct 0 ms 2052 KB Output is correct
37 Correct 0 ms 2052 KB Output is correct
38 Correct 0 ms 2052 KB Output is correct
39 Correct 0 ms 2052 KB Output is correct
40 Correct 0 ms 2052 KB Output is correct
41 Correct 0 ms 2052 KB Output is correct
42 Correct 0 ms 2052 KB Output is correct
43 Correct 0 ms 2052 KB Output is correct
44 Correct 0 ms 2052 KB Output is correct
45 Correct 0 ms 2052 KB Output is correct