# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1192137 | 27augain | Palindrome-Free Numbers (BOI13_numbers) | C++20 | 1 ms | 400 KiB |
#include <bits/stdc++.h>
using namespace std;
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1LL)
using ll = long long;
const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;
string s;
ll dp[18][11][11][2];
ll DP(int id, int lst1, int lst2, bool f) {
if (id == (int) (s.size())) {
return true;
}
if (lst1 != 10 && lst2 != 10 && dp[id][lst1][lst2][f] != -1) {
return dp[id][lst1][lst2][f];
}
ll res = 0;
for (int c = 0; c <= (f ? s[id] - '0' : 9); ++c) {
bool nwf = false;
if (f && c == s[id] - '0') {
nwf = true;
}
if (c != lst1 && c != lst2) {
res += DP(id + 1, c, lst1, nwf);
}
}
return dp[id][lst1][lst2][f] = res;
}
ll solve(ll x) {
s = to_string(x);
memset(dp, -1, sizeof(dp));
return DP(0, 10, 10, true);
}
void _27augain(void) {
ll l, r;
cin >> l >> r;
cout << solve(r) - solve(l - 1) << "\n";
}
int32_t main(void) {
#define task "27augain"
cin.tie(0)->sync_with_stdio(0);
for (string iext : {"in", "inp"}) {
if (fopen((task "." + iext).c_str(), "r")) {
freopen((task "." + iext).c_str(), "r", stdin);
freopen(task ".out", "w", stdout);
}
}
int testcase = 1;
// cin >> testcase;
while (testcase--) {
_27augain();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |