답안 #255606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255606 2020-08-01T12:25:40 Z Saboon Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
1 ms 384 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int maxn = 1e5 + 10;

ll dp[20][12][12];

ll get(string s){
	if (s.size() == 1)
		return stoi(s);
	memset(dp, 0, sizeof dp);
	for (int i = 0; i <= 9; i++)
		dp[1][10][i] = 1;
	for (int a = 0; a < 10; a++)
		for (int b = 0; b < 10; b++)
			if (a != b)
				dp[2][a][b] = 1;
	for (int len = 2; len <= 19; len++){
		for (int a = 0; a < 10; a++){
			for (int b = 0; b < 10; b++){
				if (a == b)
					continue;
				for (int c = 0; c < 10; c++){
					if (a == b or b == c)
						continue;
					dp[len][a][b] += dp[len-1][c][a];
				}
			}
		}
		for (int b = 0; b < 10; b++){
			for (int c = 0; c < 10; c++){
				if (b == c)
					continue;
				dp[len][10][b] += dp[len][b][c];
			}
		}
	}
	ll ret = 0;
	int n = s.size();
	for (int i = 0; i < n; i++){
		for (char c = '0'; c < s[i]; c++){
			if (i > 0 and c == s[i-1])
				continue;
			if (i > 1 and c == s[i-2])
				continue;
			if (i == 0)
				ret += dp[n-i][10][(int)(c-'0')];
			else
				ret += dp[n-i+1][(int)(s[i-1]-'0')][(int)(c-'0')];
		}
		if (i > 0 and s[i] == s[i-1])
			break;
		if (i > 1 and s[i] == s[i-2])
			break;
		if (i == n-1)
			ret ++;
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	ll l, r;
	cin >> l >> r;
	string a = to_string(r), b = to_string(l-1);
	if (l == 0)
		return cout << get(a) << endl, 0;
	cout << get(a) - get(b) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Correct 0 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 0 ms 384 KB Output isn't correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Incorrect 1 ms 384 KB Output isn't correct
15 Incorrect 0 ms 384 KB Output isn't correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Incorrect 0 ms 384 KB Output isn't correct
19 Correct 1 ms 384 KB Output is correct
20 Incorrect 0 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Correct 1 ms 384 KB Output is correct
7 Incorrect 0 ms 384 KB Output isn't correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 Incorrect 0 ms 384 KB Output isn't correct
10 Incorrect 0 ms 384 KB Output isn't correct
11 Correct 0 ms 384 KB Output is correct
12 Incorrect 0 ms 384 KB Output isn't correct
13 Incorrect 1 ms 384 KB Output isn't correct
14 Incorrect 1 ms 384 KB Output isn't correct
15 Incorrect 1 ms 384 KB Output isn't correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct