# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
35792 | funcsr | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 0 ms | 2268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
long long A, B;
long long dp[20][10][10][3][2];
long long solve(string X) {
rep(i, X.size()+1) rep(j, 10) rep(k, 10) rep(l, 3) rep(r, 2) dp[i][j][k][l][r] = 0;
dp[0][0][0][0][0] = 1;
rep(i, X.size()) {
int ud = X[i]-'0';
rep(j, 10) {
rep(k, 10) {
rep(s, 3) {
rep(r, 2) {
if (dp[i][j][k][s][r] == 0) continue;
rep(next, 10) {
if (s == 1 && k == next) continue;
if (s == 2 && (k == next || j == next)) continue;
if (r == 0 && next > ud) continue;
int ns = s;
if (ns == 0) {
if (next) ns++;
}
else if (ns == 1) ns++;
dp[i+1][k][next][ns][r|(next<ud)] += dp[i][j][k][s][r];
}
}
}
}
}
}
long long s = 0;
rep(i, 10) rep(j, 10) rep(k, 3) rep(r, 2) s += dp[X.size()][i][j][k][r];
return s;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> A >> B;
long long s = solve(to_string(B));
if (A > 0) s -= solve(to_string(A-1));
cout << s << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |