# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
410803 | Victor | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 1 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 1'000'000'007;
int n;
string lo, hi;
ll memo[20][11][11][2][2];
ll dp(int num, int prev, int befprev, bool l_bound, bool u_bound) {
if (num == n) return 1;
ll &ans = memo[num][prev][befprev][l_bound][u_bound];
if (ans != -1) return ans;
ans = 0;
int start = l_bound ? lo[num] - '0' : 0, stop = u_bound ? hi[num] - '0' + 1 : 10;
if (!num) start = max(start, 1);
rep(i, start, stop) {
if (i == prev || i == befprev) continue;
bool nl_bound = l_bound;
if (nl_bound && i != lo[num] - '0') nl_bound = 0;
bool nu_bound = u_bound;
if (nu_bound && i != hi[num] - '0') nu_bound = 0;
ans += dp(num + 1, i, prev, nl_bound, nu_bound);
}
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ll l, h, ans = 0;
cin >> l >> h;
if(!l)++ans;
lo = to_string(l);
hi = to_string(h);
rep(i, sz(lo), sz(hi) + 1) {
memset(memo, -1, sizeof(memo));
n = i;
ans += dp(0, 10, 10, i == sz(lo), i == sz(hi));
}
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |