# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
31356 | imaxblue | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}