답안 #1098063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098063 2024-10-09T02:44:10 Z Alihan_8 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
1 ms 360 KB
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

signed main(){
	i64 a, b; cin >> a >> b;
	
	auto f = [&](i64 x) -> i64{
		if ( x < 0 ) return 0;
		
		string s = to_string(x);
		int n = s.size();
		
		for ( auto &x: s ) x -= '0';
		
		i64 dp[n][11][11][2][2]{};
		
		for ( int j = 1; j <= s[0]; j++ ){
			dp[0][10][j][j < s[0]][1] = 1;
		} dp[0][10][10][s[0] > 0][0] = 1;
		
		for ( int i = 1; i < n; i++ ){
			for ( int j = 0; j <= 10; j++ ){
				for ( int k = 0; k <= 10; k++ ){
					for ( int c = 0; c <= 10; c++ ){
						for ( auto g: {0, 1} ){
							if ( g > 0 ){
								if ( c == 10 || c == k || c == j ) continue;
								
								for ( auto l: {0, 1} ){
									if ( !l && c > s[i] ) continue;
									
									int nxt = l || (c < s[i]);
										
									dp[i][k][c][nxt][1] += dp[i - 1][j][k][l][1];
								}
							} else{
								if ( !c ) continue;
								
								for ( auto l: {0, 1} ){
									if ( !l && c > s[i] && c != 10 ) continue;
									
									int nxt = l || (c < s[i]) || (c == 10 && s[i]), f = (c != 10);
										
									dp[i][k][c][nxt][f] += dp[i - 1][j][k][l][0];
								}
							}
						}
					}
				}
			}
		}
		
		i64 cnt = 1;
		
		for ( int x = 0; x <= 10; x++ ){
			for ( int y = 0; y <= 10; y++ ){
				for ( auto f: {0, 1} ){
					cnt += dp[n - 1][x][y][f][1];
				}
			}
		}
		
		return cnt;
	};
	
	cout << f(b) - f(a - 1) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 360 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 352 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 356 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 352 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 352 KB Output is correct