| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 696224 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 3 ms | 392 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
void print() {cerr << '\n';} template<typename T1, typename... T2> void print(T1 a, T2... b) {cerr << a << ' ', print(b...);}
vector<int> num;
ll a, b;
ll f[20][11][11][2];
ll dp(int i, int pre1, int pre2, bool smaller)
{
if(i == (int)num.size()) return 1;
ll &res = f[i][pre1 + 1][pre2 + 1][smaller];
if(~res) return res;
res = 0;
int lim = (smaller ? 9 : num[i]);
for(int d = 0; d <= lim; d++)
{
if(d == pre1 || d == pre2) continue;
res += dp(i + 1, pre2, pre2 == -1 && d == 0 ? -1 : d, smaller || (d < lim));
}
return res;
}
ll calc(ll n)
{
if(n <= 0) return n == 0;
num.clear();
while(n) num.pb(n % 10), n /= 10;
reverse(all(num));
memset(f, -1, sizeof f);
return dp(0, -1, -1, 0);
}
void solve()
{
cin >> a >> b;
cout << calc(b) - calc(a - 1);
}
signed main()
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
