# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
346692 | illequiprogrammat | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 2 ms | 492 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
struct SOLUTION {
bool vis[30][11][11][2];
// memo[index][penultimate][end_digit][tight];
ll memo[30][11][11][2];
vector<int> digits;
ll dp(int index, int penultimate, int end, bool tight) {
if (index == digits.size()) return 1;
if (vis[index][penultimate][end][tight])
return memo[index][penultimate][end][tight];
ll res = 0;
int start = 0;
int max_next = 9;
if (tight) max_next = digits[digits.size() - index - 1];
if (index == 0) start = 1;
for (int i = start; i <= max_next; i++) {
if (i != penultimate && i != end) {
res += dp(index + 1, end, i, tight && i == max_next);
}
}
vis[index][penultimate][end][tight] = true;
memo[index][penultimate][end][tight] = res;
return res;
}
void get_digits(ll n) {
while (n != 0) {
digits.push_back(n%10);
n /= 10;
}
}
bool is_palindrome() {
bool res = false;
for (int i = 0; i < digits.size()-1; i++) {
if (digits[i] == digits[i+1]) res = true;
}
for (int i = 0; i < digits.size()-2; i++) {
if (digits[i] == digits[i+2]) res = true;
}
return res;
}
};
int main() {
int a, b;
SOLUTION l_bound;
SOLUTION u_bound;
cin >> a >> b;
l_bound.get_digits(a);
ll lres = l_bound.dp(0, 0, 11, true);
u_bound.get_digits(b);
ll ures = u_bound.dp(0, 0, 11, true);
if (l_bound.is_palindrome()) {
cout << ures - lres << endl;
} else {
cout << ures - lres + 1 << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |