답안 #467019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467019 2021-08-21T10:35:43 Z ezdp Palindrome-Free Numbers (BOI13_numbers) C++14
61.6667 / 100
1 ms 332 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;
int 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) new_pass = 1;
		
		ret += f(len + 1, (new_pass ? prv2 : 10), (new_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()){
      |     ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Incorrect 1 ms 296 KB Output isn't correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Incorrect 0 ms 204 KB Output isn't correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 216 KB Output isn't correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 1 ms 296 KB Output isn't correct
22 Correct 1 ms 332 KB Output is correct
23 Incorrect 1 ms 332 KB Output isn't correct
24 Correct 1 ms 292 KB Output is correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Incorrect 1 ms 296 KB Output isn't correct
27 Incorrect 1 ms 204 KB Output isn't correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Correct 1 ms 204 KB Output is correct
33 Incorrect 1 ms 332 KB Output isn't correct
34 Correct 1 ms 332 KB Output is correct
35 Incorrect 1 ms 296 KB Output isn't correct
36 Incorrect 1 ms 332 KB Output isn't correct
37 Incorrect 1 ms 332 KB Output isn't correct
38 Incorrect 1 ms 204 KB Output isn't correct
39 Incorrect 1 ms 296 KB Output isn't correct
40 Correct 1 ms 332 KB Output is correct
41 Incorrect 1 ms 332 KB Output isn't correct
42 Correct 1 ms 292 KB Output is correct
43 Incorrect 1 ms 332 KB Output isn't correct
44 Incorrect 1 ms 204 KB Output isn't correct
45 Incorrect 1 ms 332 KB Output isn't correct