# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
629906 | typ_ik | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define watch(x) cout << (#x) << " = " << x << '\n'
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int LEN = 20;
const int NUMBER_SIZE = 11;
const int WAS_SMALLER = 2;
const int POSITIVE = 2;
ll dp[LEN][NUMBER_SIZE][NUMBER_SIZE][WAS_SMALLER][POSITIVE];
void init() {
for (int i = 0; i < LEN; i++)
for (int pl = 0; pl < NUMBER_SIZE; pl++)
for (int l = 0; l < NUMBER_SIZE; l++)
for (int w = 0; w < WAS_SMALLER; w++)
for (int p = 0; p < POSITIVE; p++)
dp[i][pl][l][w][p] = -1;
}
vector <int> d;
ll get(int pos, int pl, int l, int was, int positive) {
if (pos == d.size())
return dp[pos][pl][l][was][positive] = 1;
if (dp[pos][pl][l][was][positive] != -1)
return dp[pos][pl][l][was][positive];
int mx = d[pos];
if (was)
mx = 9;
int res = 0;
for (int nxt = 0; nxt <= mx; nxt++) {
if (nxt == pl || nxt == l)
continue;
bool currentSpace = (!nxt && !positive);
res += get(pos + 1, (currentSpace ? 10 : l), (currentSpace ? 10 : nxt), was | (nxt < d[pos]), positive | (nxt > 0));
}
return dp[pos][pl][l][was][positive] = res;
}
ll calc(ll x) {
d.clear();
while (x) d.push_back(x % 10), x /= 10;
reverse(all(d));
init();
get(0, 10, 10, 0, 0);
return dp[0][10][10][0][0];
}
void solve() {
ll a, b;
cin >> a >> b;
cout << calc(b) - calc(a - 1) << '\n';
}
main() {
boost;
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |