# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
474776 | Duy_e | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<long long, long long>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long oo = 1e18;
const long long N = 2e5 + 5;
ll dp[23][11][11][2];
vector <int> num;
ll cal(int pos, int pre, int cur, bool f){
if (pos == num.size()) return 1;
ll &ans = dp[pos][pre][cur][f];
if (ans != - 1) return ans;
ans = 0;
ll lmt = num[pos];
if (f) lmt = 9;
for (int i = 0; i <= lmt; i ++)
if (i != pre && i != cur){
bool new_f = f;
if (f == 0 && i < lmt) new_f = 1;
ans += cal(pos + 1, cur, i, new_f);
}
return ans;
}
ll solve(ll n){
memset(dp, -1, sizeof dp);
if (n < 0) return 0;
num.clear();
while (n > 0) num.push_back(n%10), n/=10;
reverse(num.begin(), num.end());
return cal(0, 10, 10, 0);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll A, B;
cin >> A >> B;
cout << solve(B) - solve(A - 1);
return 0;
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |