Submission #248563

# Submission time Handle Problem Language Result Execution time Memory
248563 2020-07-12T18:12:38 Z eohomegrownapps Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string s;

ll dpv[20][10][10][2];

ll dp(int ind, int secondlast, int last, bool isSame){
	if (ind==s.size()){
		return 1;
	}
	if (secondlast!=-1&&dpv[ind][secondlast][last][isSame]!=-1){
		return dpv[ind][secondlast][last][isSame];
	}
	int upper = isSame ? s[ind]-'0' : 9;
	ll total = 0;
	for (int i = 0; i<=upper; i++){
		if (i==last || i==secondlast){continue;}
		total+=dp(ind+1,last,i,isSame&&i==(s[ind]-'0'));
	}
	if (secondlast!=-1){
		dpv[ind][secondlast][last][isSame]=total;
	}
	return total;
}

void initdp(){
	for (int i = 0; i<20; i++){
		for (int j = 0; j<10; j++){
			for (int k = 0; k<10; k++){
				for (int l = 0; l<2; l++){
					dpv[i][j][k][l]=-1;
				}
			}
		}
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	ll a,b;
	cin>>a>>b;
	a--;
	s=to_string(b);
	initdp();
	ll tot = dp(0,-1,-1,true);
	if (a>=0){
		s=to_string(a);
		initdp();
		tot-=dp(0,-1,-1,true);
	}
	cout<<tot<<'\n';
}

Compilation message

numbers.cpp: In function 'll dp(int, int, int, bool)':
numbers.cpp:10:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (ind==s.size()){
      ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Incorrect 0 ms 384 KB Output isn't correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Incorrect 0 ms 384 KB Output isn't correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Correct 0 ms 384 KB Output is correct
7 Incorrect 0 ms 384 KB Output isn't correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 Incorrect 0 ms 384 KB Output isn't correct
10 Incorrect 0 ms 384 KB Output isn't correct
11 Correct 0 ms 384 KB Output is correct
12 Incorrect 0 ms 384 KB Output isn't correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Incorrect 0 ms 384 KB Output isn't correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct