Submission #31356

# Submission time Handle Problem Language Result Execution time Memory
31356 2017-08-19T14:52:17 Z imaxblue Palindrome-Free Numbers (BOI13_numbers) C++14
Compilation error
0 ms 0 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;
    drain(dp);
    dp[10][10][0][0]=1;
    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];
                    }
                }
            }
        }
    }
    ll ans=0;
    fox(l, 11){
        fox(l2, 11){
            ans+=dp[l][l2][p][0];
        }
    }
    //cout << ans << endl;
    return ans;
}
int main(){
    cin >> x >> y;
    cout << solve(y)-solve(x-1) << endl;
    return 0;
}

Compilation message

Compilation timeout while compiling numbers