Submission #558783

# Submission time Handle Problem Language Result Execution time Memory
558783 2022-05-08T10:30:00 Z mr_slappy Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
1 ms 340 KB
#include "bits/stdc++.h"
#define int long long
using namespace std;
int n;
int a[20];
int dp[20][2][11][11];

int cnt(int pos,int k,int fi,int se)
{
	// cout<<pos<<' '<<k<<" "<<fi<<" "<<se<<'\n';
	if(pos==n) return 1;
	if(dp[pos][k][fi][se]!=-1) return dp[pos][k][fi][se];
	int upper=a[pos];
	if(k) upper=9;
	int ans=0;
	for(int i=0;i<=upper;i++)
	{
		if(i==fi or i==se) continue;
		if(i==0 and fi==10 and se==10)
		{
			ans+=cnt(pos+1,1,fi,se);
		}
		else
		{
			ans+=cnt(pos+1,(k or i<a[pos]),se,i);
		}
	}
	return dp[pos][k][fi][se]=ans;
}

int solve(int x)
{
	memset(dp,-1,sizeof(dp));
	n=0;
	while(x)
	{
		a[n++]=x%10;
		x/=10;
	}
	reverse(a,a+n);
	return cnt(0,0,10,10);
}

signed main()
{
	int l,r;
	cin>>l>>r;
	cout<<solve(r)-solve(l-1);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 308 KB Output is correct
45 Correct 1 ms 340 KB Output is correct