QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760065 | #7954. Special Numbers | LittlePants | WA | 0ms | 3852kb | C++14 | 3.2kb | 2024-11-18 14:29:45 | 2024-11-18 14:29:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define X first
#define Y second
#define F first
#define S second
#define vi vector<int>
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(ALL(x), v)
#define ub(x, v) upper_bound(ALL(x), v)
#define re(x) reverse(ALL(x))
#define uni(x) x.resize(unique(ALL(x)) - x.begin())
#define inf 1000000000
#define INF 1000000000000000000
#define mod 1000000007
#define MOD 998244353
#define get_bit(x, y) ((x>>y)&1)
#define mkp make_pair
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cerr << a << ' ', abc(b...);
}
#ifdef debug
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
template<class T> bool ckmin(T& a, const T& b) { return b<a ? a=b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a<b ? a=b, 1 : 0; }
const vector<int> prime = {2, 3, 5, 7};
vector<vector<int>> states;
map<pii, ll> dp;
vector<int> fac;
ll goal;
ll myhash(const vector<int> &v) {
ll res = 0;
if (v[4] == 1) return -1;
for (int i = 0; i < 4; i++) {
res = res * 100 + v[i];
}
return res;
}
vector<int> decode(ll hsh) {
vector<int> v;
if (hsh == -1) return vector<int>({0, 0, 0, 0, 1});
for (int i = 0; i < 4; i++) {
v.eb(hsh % 100);
hsh /= 100;
}
reverse(ALL(v));
return v;
}
vector<int> add_fac(const vector<int> &cur_fac, int x) {
vector<int> res(5);
if (x == 0) {
res[4] = 1;
return res;
}
for (int i = 0; i < 4; i++) {
int j = prime[i], cnt = 0;
while (x % j == 0) {
x /= j;
cnt++;
}
res[i] = min(fac[i], cur_fac[i] + cnt);
}
return res;
}
ll dfs(int pos, int hsh, int lim, const vector<int> &num) {
if (pos == -1) return hsh == goal || hsh == -1;
if (!lim && dp.find(mkp(pos, hsh)) != dp.end()) return dp[mkp(pos, hsh)];
int ub = (lim ? num[pos] : 9);
vector<int> cur_fac = decode(hsh);
ll res = 0;
for (int i = 0; i <= ub; i++) {
auto nxt = add_fac(cur_fac, i);
res = (res + dfs(pos - 1, myhash(nxt), lim && i == ub, num)) % mod;
}
if (!lim) dp[mkp(pos, hsh)] = res;
return res;
}
ll cal(ll x) {
if (x == 0) return 1;
vector<int> num;
int dig_cnt = 0;
while (x) {
num.eb(x % 10);
x /= 10;
dig_cnt++;
}
test(dig_cnt);
return dfs(dig_cnt - 1, 0, 1, num);
}
void get_allstates(int pos, vector<int> cur = {}) {
if (pos == 4) {
states.eb(cur);
return;
}
for (int i = 0; i <= fac[pos]; i++) {
cur.eb(i);
get_allstates(pos + 1, cur);
cur.pop_back();
}
}
inline void solve() {
ll k, l, r;
cin >> k >> l >> r;
fac.resize(4);
for (int i = 0; i < 4; i++) {
int j = prime[i];
while (k % j == 0) {
k /= j;
fac[i]++;
}
}
goal = myhash(fac);
get_allstates(0);
test(SZ(states));
test(cal(r));
test(cal(l - 1));
cout << cal(r) - cal(l - 1);
}
signed main() {
IO;
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 100 100000
output:
99901
result:
ok single line: '99901'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3620kb
input:
10 800 43021
output:
14395
result:
wrong answer 1st lines differ - expected: '23570', found: '14395'