# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1184403 | knhatdev | Palindrome-Free Numbers (BOI13_numbers) | C++20 | 0 ms | 328 KiB |
#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define task ""
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7;
int n, a[N], dp[20][2][15][15];
int cal(int pos, bool tight, int x, int y){
if(pos > n) return 1;
if(dp[pos][tight][x][y] != -1) return dp[pos][tight][x][y];
int &res = dp[pos][tight][x][y];
res = 0;
for(int i = 0; i <= (tight ? a[pos] : 9); i++){
if(i == y) continue;
if(i == x) continue;
res += cal(pos + 1, (tight & i == a[pos]), y, i);
}
return res;
}
int sol(int x){
n = 0;
if(x == 0) return 1;
while(x){
a[++n] = x % 10;
x /= 10;
}
int l = 1, r = n;
while(l < r){
swap(a[l], a[r]);
l++; r--;
}
// for(int i = 1; i <= n; i++) cout << a[i];
// cout << '\n';
memset(dp, -1, sizeof dp);
return cal(1, 1, 10, 10);
}
main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(task ".inp", "r")){
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
int a, b;
cin >> a >> b;
if(a == 0){
cout << sol(b);
return 0;
}
cout << sol(b) - sol(a - 1);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |