# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26379 | 2017-06-29T13:57:04 Z | samir_droubi | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 0 ms | 2040 KB |
#include <bits/stdc++.h> using namespace std; long long a,b; long long dp[20][12][12]; long long calc(int i,int lst1,int lst2) { if(i==2)return lst1!=lst2; if(dp[i][lst1][lst2]!=-1)return dp[i][lst1][lst2]; long long ans=0; for(int j=0;j<=9;++j) { if(j!=lst1&&j!=lst2) ans=ans+calc(i-1,j,lst1); } return dp[i][lst1][lst2]=ans; } long long sm[20]; vector<int>v; long long f(long long x) { v.clear(); int y=x; while(x!=0) { v.push_back(x%10); x/=10; } if(v.size()==1) return y-1; if(v.size()==2) return y-1-(v[1]-1)-(v[0]-1>=v[1]); long long ans=0; for(int i=0;i<v.size();++i) { int lst1=10; int lst2=10; if(i<v.size()-1)lst1=v[i+1]; if(i<v.size()-2)lst2=v[i+2]; if(i<v.size()-1&&v[i]==v[i+1])ans=0; if(i<v.size()-2&&v[i]==v[i+2])ans=0; for(int j=(i==v.size()-1);j<v[i];++j) { if(j==lst2||j==lst1)continue; ans=ans+calc(i+2,j,lst1); } } return ans+sm[v.size()-1]; } int main() { memset(dp,-1,sizeof dp); scanf("%lld%lld",&a,&b); sm[1]=9; for(int i=2;i<=18;++i) { for(int j=1;j<=9;++j) for(int k=0;k<=9;++k) sm[i]+=calc(i,j,k); sm[i]+=sm[i-1]; } long long sa=f(a); long long sb=f(b+1); printf("%lld\n",sb-sa); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2040 KB | Output is correct |
2 | Correct | 0 ms | 2040 KB | Output is correct |
3 | Correct | 0 ms | 2040 KB | Output is correct |
4 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
5 | Correct | 0 ms | 2040 KB | Output is correct |
6 | Correct | 0 ms | 2040 KB | Output is correct |
7 | Correct | 0 ms | 2040 KB | Output is correct |
8 | Correct | 0 ms | 2040 KB | Output is correct |
9 | Correct | 0 ms | 2040 KB | Output is correct |
10 | Correct | 0 ms | 2040 KB | Output is correct |
11 | Correct | 0 ms | 2040 KB | Output is correct |
12 | Correct | 0 ms | 2040 KB | Output is correct |
13 | Correct | 0 ms | 2040 KB | Output is correct |
14 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
15 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
16 | Correct | 0 ms | 2040 KB | Output is correct |
17 | Correct | 0 ms | 2040 KB | Output is correct |
18 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
19 | Correct | 0 ms | 2040 KB | Output is correct |
20 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2040 KB | Output is correct |
2 | Correct | 0 ms | 2040 KB | Output is correct |
3 | Correct | 0 ms | 2040 KB | Output is correct |
4 | Correct | 0 ms | 2040 KB | Output is correct |
5 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
6 | Correct | 0 ms | 2040 KB | Output is correct |
7 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
8 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
9 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
10 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
11 | Correct | 0 ms | 2040 KB | Output is correct |
12 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
13 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
14 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
15 | Incorrect | 0 ms | 2040 KB | Output isn't correct |
16 | Correct | 0 ms | 2040 KB | Output is correct |
17 | Correct | 0 ms | 2040 KB | Output is correct |
18 | Correct | 0 ms | 2040 KB | Output is correct |
19 | Correct | 0 ms | 2040 KB | Output is correct |
20 | Correct | 0 ms | 2040 KB | Output is correct |
21 | Correct | 0 ms | 2040 KB | Output is correct |
22 | Correct | 0 ms | 2040 KB | Output is correct |
23 | Correct | 0 ms | 2040 KB | Output is correct |
24 | Correct | 0 ms | 2040 KB | Output is correct |
25 | Correct | 0 ms | 2040 KB | Output is correct |
26 | Correct | 0 ms | 2040 KB | Output is correct |
27 | Correct | 0 ms | 2040 KB | Output is correct |
28 | Correct | 0 ms | 2040 KB | Output is correct |
29 | Correct | 0 ms | 2040 KB | Output is correct |
30 | Correct | 0 ms | 2040 KB | Output is correct |
31 | Correct | 0 ms | 2040 KB | Output is correct |
32 | Correct | 0 ms | 2040 KB | Output is correct |
33 | Correct | 0 ms | 2040 KB | Output is correct |
34 | Correct | 0 ms | 2040 KB | Output is correct |
35 | Correct | 0 ms | 2040 KB | Output is correct |
36 | Correct | 0 ms | 2040 KB | Output is correct |
37 | Correct | 0 ms | 2040 KB | Output is correct |
38 | Correct | 0 ms | 2040 KB | Output is correct |
39 | Correct | 0 ms | 2040 KB | Output is correct |
40 | Correct | 0 ms | 2040 KB | Output is correct |
41 | Correct | 0 ms | 2040 KB | Output is correct |
42 | Correct | 0 ms | 2040 KB | Output is correct |
43 | Correct | 0 ms | 2040 KB | Output is correct |
44 | Correct | 0 ms | 2040 KB | Output is correct |
45 | Correct | 0 ms | 2040 KB | Output is correct |