답안 #228738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228738 2020-05-02T12:48:19 Z Haunted_Cpp Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
6 ms 512 KB
#include <iostream>
#include <vector>
#include <cstring>
#include <cassert>
#include <bitset>
 
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
using namespace std;

long long dp [20][11][11][2];

vector<int> lim;
const int OFF=  1;

long long solve (int p, int last1, int last2, bool started, bool tight) {
	if (p < 0) return 1;
	if (tight && ~dp[p][last1 + OFF][last2 + OFF][started]) return dp[p][last1 + OFF][last2 + OFF][started];
	long long res = 0;
	if (!started) {
		res += solve (p - 1, last1, last2, false, true);
	}
	for (int i = (started ? 0 : 1) ; i <= (tight ? 9 : lim[p]); i++) {
		int ant = last1 - OFF;
		int antant = last2 - OFF;
		int dig = i;
		if (dig != ant && dig != antant) {
			res += solve (p - 1, dig + OFF, ant + OFF, true, tight | (i < lim[p]));
		}
	}
	return (!tight ? res : dp[p][last1 + OFF][last2 + OFF][started] = res);
}

long long get_solve (long long n) {
	if (n < 0) return 0;
	lim.clear();
	while (n) {
		lim.emplace_back(n % 10);
		n /= 10;
	}
	return solve ( (int) lim.size() - 1, -1 + OFF, -1 + OFF, false, false);
}
 
int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset (dp, -1, sizeof(dp));
  long long lo, hi;
  cin >> lo >> hi;
  cout << get_solve (hi) - get_solve (lo - 1) << '\n';
  return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct