Submission #68098

# Submission time Handle Problem Language Result Execution time Memory
68098 2018-08-15T22:24:27 Z thebes Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
4 ms 1144 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll dp[20][11][11][2], N, a, b;
string s;
ll solve(ll n,ll a,ll b,ll m){
	if(n==s.size()) return 1;
	else if(dp[n][a][b][m]!=-1) return dp[n][a][b][m];
	else{
		dp[n][a][b][m] = 0;
		ll &val = dp[n][a][b][m];
		for(int i=0;i<=(m?s[n]-'0':9);i++){
			if(i==a||i==b) continue;
			if(i==0&&b==10&&a==10) val+=solve(n+1,a,b,0);
			else val+=solve(n+1,i,a,m&&i==s[n]-'0');
		}
		return dp[n][a][b][m];
	}
}
ll solve(){
	memset(dp, -1, sizeof(dp));
	return solve(0,10,10,1);
}
int main(){
	cin >> N; s=to_string(N-1);
	if(N-1==-1) a = 0;
	else a = solve(); 
	cin >> N; s=to_string(N);
	b = solve();
	printf("%lld\n",b-a);
	return 0;
}

Compilation message

numbers.cpp: In function 'll solve(ll, ll, ll, ll)':
numbers.cpp:8:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(n==s.size()) return 1;
     ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 580 KB Output is correct
3 Correct 3 ms 700 KB Output is correct
4 Correct 4 ms 700 KB Output is correct
5 Correct 3 ms 700 KB Output is correct
6 Correct 3 ms 700 KB Output is correct
7 Correct 3 ms 700 KB Output is correct
8 Correct 3 ms 700 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 4 ms 752 KB Output is correct
11 Correct 3 ms 756 KB Output is correct
12 Correct 3 ms 888 KB Output is correct
13 Correct 2 ms 888 KB Output is correct
14 Correct 2 ms 888 KB Output is correct
15 Correct 2 ms 888 KB Output is correct
16 Correct 3 ms 924 KB Output is correct
17 Correct 2 ms 924 KB Output is correct
18 Correct 2 ms 924 KB Output is correct
19 Correct 4 ms 924 KB Output is correct
20 Correct 2 ms 924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 924 KB Output is correct
2 Correct 3 ms 924 KB Output is correct
3 Correct 2 ms 924 KB Output is correct
4 Correct 3 ms 924 KB Output is correct
5 Correct 3 ms 924 KB Output is correct
6 Correct 2 ms 1036 KB Output is correct
7 Correct 2 ms 1036 KB Output is correct
8 Correct 2 ms 1036 KB Output is correct
9 Correct 3 ms 1036 KB Output is correct
10 Correct 2 ms 1036 KB Output is correct
11 Correct 3 ms 1036 KB Output is correct
12 Correct 3 ms 1036 KB Output is correct
13 Correct 3 ms 1036 KB Output is correct
14 Correct 3 ms 1036 KB Output is correct
15 Correct 2 ms 1036 KB Output is correct
16 Correct 4 ms 1036 KB Output is correct
17 Correct 2 ms 1036 KB Output is correct
18 Correct 2 ms 1036 KB Output is correct
19 Correct 3 ms 1036 KB Output is correct
20 Correct 3 ms 1036 KB Output is correct
21 Correct 2 ms 1036 KB Output is correct
22 Correct 2 ms 1036 KB Output is correct
23 Correct 3 ms 1036 KB Output is correct
24 Correct 3 ms 1036 KB Output is correct
25 Correct 3 ms 1036 KB Output is correct
26 Correct 3 ms 1036 KB Output is correct
27 Correct 3 ms 1112 KB Output is correct
28 Correct 3 ms 1144 KB Output is correct
29 Correct 2 ms 1144 KB Output is correct
30 Correct 3 ms 1144 KB Output is correct
31 Correct 3 ms 1144 KB Output is correct
32 Correct 3 ms 1144 KB Output is correct
33 Correct 2 ms 1144 KB Output is correct
34 Correct 4 ms 1144 KB Output is correct
35 Correct 3 ms 1144 KB Output is correct
36 Correct 3 ms 1144 KB Output is correct
37 Correct 3 ms 1144 KB Output is correct
38 Correct 3 ms 1144 KB Output is correct
39 Correct 3 ms 1144 KB Output is correct
40 Correct 3 ms 1144 KB Output is correct
41 Correct 3 ms 1144 KB Output is correct
42 Correct 3 ms 1144 KB Output is correct
43 Correct 2 ms 1144 KB Output is correct
44 Correct 3 ms 1144 KB Output is correct
45 Correct 3 ms 1144 KB Output is correct