Submission #368198

# Submission time Handle Problem Language Result Execution time Memory
368198 2021-02-19T18:42:56 Z knightron0 Palindrome-Free Numbers (BOI13_numbers) C++14
73.75 / 100
1 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double

const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;

string s1, s2;
int dp[20][12][12][3][3];

int solve(int idx, int p1, int p2, bool same_upper, bool same_lower){
	if(idx == s2.size()) {
		return 1;
	}
	if(dp[idx][p1][p2][same_upper][same_lower] != -1){
		return dp[idx][p1][p2][same_upper][same_lower];
	}
	int lo = s1[idx]-'0';
	int hi = s2[idx]-'0';
	int ans = 0;
	for(int i= 0;i<10;i++){
		bool valid =true;
		if(same_lower){
			if(i < lo) valid = false;
		}
		if(same_upper){
			if(i > hi) valid = false;
		}
		if(i == p1-1 || i == p2-1) valid = false;
		if(!valid) continue;
		bool newb1 = (lo ==i) & same_lower;
		bool newb2 = (hi ==i) & same_upper;
		ans += solve(idx+1, i+1, p1, newb2, newb1);
	}
	return dp[idx][p1][p2][same_upper][same_lower] = ans;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif
    cin>>s1>>s2;
    clr(dp, -1);
    while(s1.size() != s2.size()){
    	s1 = '0'+s1;
    }
    cout<<solve(0, 0, 0, 1, 1)<<endl;
    return 0;
}



Compilation message

numbers.cpp: In function 'long long int solve(long long int, long long int, long long int, bool, bool)':
numbers.cpp:25:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  if(idx == s2.size()) {
      |     ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Incorrect 1 ms 492 KB Output isn't correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Correct 1 ms 492 KB Output is correct
6 Incorrect 1 ms 492 KB Output isn't correct
7 Incorrect 1 ms 492 KB Output isn't correct
8 Incorrect 1 ms 628 KB Output isn't correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Incorrect 1 ms 492 KB Output isn't correct
15 Incorrect 1 ms 492 KB Output isn't correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Incorrect 1 ms 492 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Incorrect 1 ms 492 KB Output isn't correct
6 Correct 1 ms 492 KB Output is correct
7 Incorrect 1 ms 492 KB Output isn't correct
8 Incorrect 1 ms 492 KB Output isn't correct
9 Incorrect 1 ms 492 KB Output isn't correct
10 Incorrect 1 ms 492 KB Output isn't correct
11 Correct 1 ms 492 KB Output is correct
12 Incorrect 1 ms 492 KB Output isn't correct
13 Incorrect 1 ms 492 KB Output isn't correct
14 Incorrect 1 ms 492 KB Output isn't correct
15 Incorrect 1 ms 492 KB Output isn't correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 504 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 620 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 492 KB Output is correct
45 Correct 1 ms 492 KB Output is correct