# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
547250 | Jomnoi | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 2 ms | 360 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
long long dp[20][2][11][11];
long long solve2(string s, int idx = 0, bool f = false, int p1 = 10, int p2 = 10) {
if(dp[idx][f][p1][p2] != -1) {
return dp[idx][f][p1][p2];
}
if(idx == s.size()) {
return 1;
}
int len = 9;
if(f == false) {
len = s[idx] - '0';
}
long long res = 0;
for(int i = 0; i <= len; i++) {
bool nf = f;
if(i < len) {
nf = true;
}
if(i == p1 or i == p2) {
continue;
}
res += solve2(s, idx + 1, nf, i, p1);
}
return dp[idx][f][p1][p2] = res;
}
long long solve(long long a) {
for(int i = 0; i < 20; i++) {
for(int j = 0; j <= 10; j++) {
for(int k = 0; k <= 10; k++) {
dp[i][0][j][k] = dp[i][1][j][k] = -1;
}
}
}
string t;
while(a > 0) {
t.push_back(a % 10 + '0');
a /= 10;
}
reverse(t.begin(), t.end());
return solve2(t);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
long long a, b, ans;
cin >> a >> b;
ans = solve(b);
if(a > 0) {
ans -= solve(a - 1);
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |