# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
77607 | xiaowuc1 | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 3 ms | 924 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;
const double PI = 2 * acos(0);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;
ll dp[25][11][11][2];
bool seen[25][11][11][2];
ll solve(vector<int>& digits, int idx, int a, int b, int constrained) {
if(seen[idx][a][b][constrained]) return dp[idx][a][b][constrained];
seen[idx][a][b][constrained] = true;
if(idx == digits.size()) {
dp[idx][a][b][constrained] = 1;
return 1;
}
for(int i = 0; i <= 9 && (i <= digits[idx] || !constrained); i++) {
if(i == a || i == b) continue;
int nc = constrained == 1 && i == digits[idx] ? 1 : 0;
dp[idx][a][b][constrained] += solve(digits, idx+1, b, i, nc);
}
return dp[idx][a][b][constrained];
}
ll solve(ll n) {
if(n < 0) return 0;
vector<int> digits;
while(n) {
digits.push_back(n%10);
n /= 10;
}
reverse(digits.begin(), digits.end());
memset(dp, 0, sizeof(dp));
memset(seen, 0, sizeof(seen));
return solve(digits, 0, 10, 10, 1);
}
int main() {
ll a, b;
scanf("%lld %lld", &a, &b);
printf("%lld\n", solve(b) - solve(a-1));
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |