답안 #77209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77209 2018-09-24T01:48:45 Z ToMoClone Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
3 ms 740 KB
/*input
123 321
*/
#include <bits/stdc++.h>
using namespace std;

int64_t f[20][10][10][2];

vector<int> convert(int64_t x) {
	vector<int> v;
	if(x == 0) {v.push_back(x); return v;}
	while(x > 0) v.push_back(x % 10), x /= 10;
	reverse(v.begin(), v.end()); return move(v);
}

int64_t cal(vector<int> x) {	
	memset(f, 0, sizeof f);
	int n = (int)x.size();

	if(n == 1) return x[0];
	for(int i = 10; i < 100; ++ i)
		for(int j = 0; j + 1 < n; ++ j)
			if((i / 10) != (i % 10) && (j || (i / 10 <= x[j]))) {
				if((j == 0) && (i / 10 == x[j]) && (i % 10 > x[j + 1])) continue;
				f[j + 1][i / 10][i % 10][j || (i / 10 < x[j]) || (i % 10 < x[j + 1])] = 1;
			}

	for(int i = 1; i < n - 1; ++ i)
		for(int num1 = 0; num1 <= 9; ++ num1)
			for(int num2 = 0; num2 <= 9; ++ num2)
				for(int nxt = 0; nxt <= 9; ++ nxt) if(num1 != nxt && num2 != nxt) {
					f[i + 1][num2][nxt][1] += f[i][num1][num2][1];
					if(nxt == x[i + 1]) f[i + 1][num2][nxt][0] += f[i][num1][num2][0];
					if(nxt < x[i + 1]) f[i + 1][num2][nxt][1] += f[i][num1][num2][0];
				}

	int64_t Ans = 0;
	for(int i = 0; i <= 9; ++ i)
		for(int j = 0; j <= 9; ++ j) Ans += f[n - 1][i][j][1];
	return Ans + 10;
}

int main(){
	int64_t a, b; cin >> a >> b;
	// cout << cal(convert(b + 1)) << ' ' << cal(convert(a)) << endl;
	cout << cal(convert(b + 1)) - cal(convert(a)) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 536 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 680 KB Output is correct
15 Correct 2 ms 680 KB Output is correct
16 Correct 2 ms 680 KB Output is correct
17 Correct 2 ms 680 KB Output is correct
18 Correct 2 ms 680 KB Output is correct
19 Correct 2 ms 680 KB Output is correct
20 Correct 2 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 680 KB Output is correct
2 Correct 2 ms 680 KB Output is correct
3 Correct 2 ms 680 KB Output is correct
4 Correct 2 ms 740 KB Output is correct
5 Correct 2 ms 740 KB Output is correct
6 Correct 2 ms 740 KB Output is correct
7 Correct 2 ms 740 KB Output is correct
8 Correct 2 ms 740 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 2 ms 740 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 2 ms 740 KB Output is correct
13 Correct 2 ms 740 KB Output is correct
14 Correct 2 ms 740 KB Output is correct
15 Correct 2 ms 740 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 3 ms 740 KB Output is correct
18 Correct 2 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 2 ms 740 KB Output is correct
26 Correct 2 ms 740 KB Output is correct
27 Correct 2 ms 740 KB Output is correct
28 Correct 2 ms 740 KB Output is correct
29 Correct 2 ms 740 KB Output is correct
30 Correct 2 ms 740 KB Output is correct
31 Correct 2 ms 740 KB Output is correct
32 Correct 2 ms 740 KB Output is correct
33 Correct 2 ms 740 KB Output is correct
34 Correct 2 ms 740 KB Output is correct
35 Correct 2 ms 740 KB Output is correct
36 Correct 2 ms 740 KB Output is correct
37 Correct 2 ms 740 KB Output is correct
38 Correct 2 ms 740 KB Output is correct
39 Correct 2 ms 740 KB Output is correct
40 Correct 2 ms 740 KB Output is correct
41 Correct 2 ms 740 KB Output is correct
42 Correct 2 ms 740 KB Output is correct
43 Correct 2 ms 740 KB Output is correct
44 Correct 2 ms 740 KB Output is correct
45 Correct 2 ms 740 KB Output is correct