Submission #77213

# Submission time Handle Problem Language Result Execution time Memory
77213 2018-09-24T02:03:22 Z Dat160601 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
3 ms 936 KB
#include <bits/stdc++.h>
using namespace std;
long long a,b;
long long len_a=0,len_b=0;
long long digit_a[20],digit_b[20];
long long dp[20][2][2][2][11][11];
long long go(int id,int ft,int l,int r,int prv,int pv){
	if(id==0) return 1LL;
	if(dp[id][ft][l][r][prv][pv]!=-1) return dp[id][ft][l][r][prv][pv];
	long long ret=0;
	for(int i=0;i<=9;i++){
		if(ft && i==0) continue;
		if(l==1 && i<digit_a[id]) continue;
		if(r==1 && i>digit_b[id]) continue;
		if(i==prv || i==pv) continue;
		ret+=go(id-1,0,(l==1 && i==digit_a[id])?1:0,(r==1 && i==digit_b[id])?1:0,pv,i);
	}
	dp[id][ft][l][r][prv][pv]=ret;
	return ret;
}
int main(){
	scanf("%lld %lld",&a,&b);
	long long x=a;
	while(x>0){
		digit_a[++len_a]=x%10;
		x/=10;
	}
	x=b;
	while(x>0){
		digit_b[++len_b]=x%10;
		x/=10;
	}
	memset(dp,-1,sizeof(dp));
	long long ans=0;
	for(int i=len_b;i>=len_a;i--){
		int ok1=1,ok2=1;
		if(i<len_b) ok2=0;
		if(i>len_a) ok1=0;
		ans+=go(i,1,ok1,ok2,10,10);
	}
	printf("%lld",ans);
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&a,&b);
  ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 568 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 816 KB Output is correct
15 Correct 2 ms 816 KB Output is correct
16 Correct 2 ms 816 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 2 ms 816 KB Output is correct
19 Correct 2 ms 936 KB Output is correct
20 Correct 2 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 936 KB Output is correct
2 Correct 2 ms 936 KB Output is correct
3 Correct 2 ms 936 KB Output is correct
4 Correct 2 ms 936 KB Output is correct
5 Correct 2 ms 936 KB Output is correct
6 Correct 2 ms 936 KB Output is correct
7 Correct 2 ms 936 KB Output is correct
8 Correct 2 ms 936 KB Output is correct
9 Correct 2 ms 936 KB Output is correct
10 Correct 2 ms 936 KB Output is correct
11 Correct 2 ms 936 KB Output is correct
12 Correct 2 ms 936 KB Output is correct
13 Correct 2 ms 936 KB Output is correct
14 Correct 2 ms 936 KB Output is correct
15 Correct 2 ms 936 KB Output is correct
16 Correct 2 ms 936 KB Output is correct
17 Correct 2 ms 936 KB Output is correct
18 Correct 2 ms 936 KB Output is correct
19 Correct 2 ms 936 KB Output is correct
20 Correct 2 ms 936 KB Output is correct
21 Correct 2 ms 936 KB Output is correct
22 Correct 2 ms 936 KB Output is correct
23 Correct 3 ms 936 KB Output is correct
24 Correct 2 ms 936 KB Output is correct
25 Correct 2 ms 936 KB Output is correct
26 Correct 2 ms 936 KB Output is correct
27 Correct 2 ms 936 KB Output is correct
28 Correct 2 ms 936 KB Output is correct
29 Correct 2 ms 936 KB Output is correct
30 Correct 2 ms 936 KB Output is correct
31 Correct 2 ms 936 KB Output is correct
32 Correct 2 ms 936 KB Output is correct
33 Correct 2 ms 936 KB Output is correct
34 Correct 2 ms 936 KB Output is correct
35 Correct 2 ms 936 KB Output is correct
36 Correct 2 ms 936 KB Output is correct
37 Correct 2 ms 936 KB Output is correct
38 Correct 2 ms 936 KB Output is correct
39 Correct 2 ms 936 KB Output is correct
40 Correct 2 ms 936 KB Output is correct
41 Correct 2 ms 936 KB Output is correct
42 Correct 2 ms 936 KB Output is correct
43 Correct 2 ms 936 KB Output is correct
44 Correct 2 ms 936 KB Output is correct
45 Correct 2 ms 936 KB Output is correct