Submission #467016

# Submission time Handle Problem Language Result Execution time Memory
467016 2021-08-21T10:23:32 Z ezdp Palindrome-Free Numbers (BOI13_numbers) C++14
26.25 / 100
23 ms 368 KB
#pragma GCC target ("sse4")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx&(-idx)
#define bin(x) bitset<32>(x).to_string()
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;

using namespace std;
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using matrix = vector<vector<T>>;
/// find_by_order(x) -> x-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x)		 -> inserts x into the set

string n;
ll dp[19][11][11][2][2];

ll f(ll len = 0, ll prv1 = 10, ll prv2 = 10, bool flag = 0, bool pass = 0){
	if(len == n.size()){
		return 1;
	}
	if(dp[len][prv1][prv2][flag][pass] != -1)
		return dp[len][prv1][prv2][flag][pass];
	ll ret = 0, limit = (flag ? 9 : n[len] - '0');
	for(int dgt = 0; dgt <= limit; dgt ++){
		if(dgt == prv1 || dgt == prv2) continue;
		
		bool new_flag = flag;
		bool new_pass = pass;
		
		if(dgt < limit) new_flag = true;
		if(dgt) pass = 1;
		
		ret += f(len + 1, (pass ? prv2 : 10), (pass ? dgt : 10), new_flag, new_pass);
	}
	return dp[len][prv1][prv2][flag][pass] = ret;
}

ll s(ll x){
	n.clear();
	while(x){
		n += (char)((x % 10) + '0');
		x /= 10;
	}
	reverse(all(n));
	memset(dp, -1, sizeof(dp));
	return (n.empty() ? 0 : f());
}

int main(){
	/// ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll a, b; cin >> a >> b;
	cout << (a ? s(b) - s(a - 1) : s(b)) << endl;
}
/**

*/

Compilation message

numbers.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("O3")
      | 
numbers.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("unroll-loops")
      | 
numbers.cpp: In function 'long long int f(long long int, long long int, long long int, bool, bool)':
numbers.cpp:33: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]
   33 |  if(len == n.size()){
      |     ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 10 ms 364 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Incorrect 0 ms 332 KB Output isn't correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Incorrect 1 ms 332 KB Output isn't correct
19 Incorrect 11 ms 296 KB Output isn't correct
20 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 296 KB Output isn't correct
2 Incorrect 20 ms 332 KB Output isn't correct
3 Incorrect 20 ms 332 KB Output isn't correct
4 Incorrect 20 ms 332 KB Output isn't correct
5 Incorrect 1 ms 296 KB Output isn't correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 Incorrect 1 ms 332 KB Output isn't correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 23 ms 364 KB Output isn't correct
17 Correct 19 ms 360 KB Output is correct
18 Correct 19 ms 364 KB Output is correct
19 Correct 19 ms 332 KB Output is correct
20 Correct 19 ms 332 KB Output is correct
21 Incorrect 19 ms 296 KB Output isn't correct
22 Correct 10 ms 332 KB Output is correct
23 Incorrect 20 ms 332 KB Output isn't correct
24 Correct 23 ms 332 KB Output is correct
25 Incorrect 19 ms 332 KB Output isn't correct
26 Incorrect 21 ms 364 KB Output isn't correct
27 Incorrect 19 ms 360 KB Output isn't correct
28 Incorrect 20 ms 332 KB Output isn't correct
29 Correct 14 ms 332 KB Output is correct
30 Correct 20 ms 364 KB Output is correct
31 Incorrect 22 ms 364 KB Output isn't correct
32 Correct 19 ms 332 KB Output is correct
33 Incorrect 10 ms 332 KB Output isn't correct
34 Correct 20 ms 368 KB Output is correct
35 Incorrect 19 ms 332 KB Output isn't correct
36 Incorrect 19 ms 332 KB Output isn't correct
37 Incorrect 10 ms 332 KB Output isn't correct
38 Incorrect 19 ms 360 KB Output isn't correct
39 Incorrect 21 ms 332 KB Output isn't correct
40 Correct 20 ms 364 KB Output is correct
41 Incorrect 19 ms 364 KB Output isn't correct
42 Correct 21 ms 364 KB Output is correct
43 Incorrect 19 ms 332 KB Output isn't correct
44 Incorrect 19 ms 360 KB Output isn't correct
45 Incorrect 19 ms 360 KB Output isn't correct