QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#298440 | #7953. Product Delivery | SolitaryDream# | WA | 7ms | 494964kb | C++17 | 1.5kb | 2024-01-06 09:54:15 | 2024-01-06 09:54:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
using sit = string::iterator;
const int pri[] = {2, 3, 5, 7};
const int p = 1e9 + 7;
int f[24][70][45][32][26];
inline vector<int> Dec(vector<int> cnt, int val, int pz) {
if (!pz && val == 0) return {0, 0, 0, 0};
for (int i = 0; i < 4; ++i) {
while (cnt[i] && val % pri[i] == 0) val /= pri[i], --cnt[i];
}
return cnt;
}
inline int Dp(sit cur, sit ed, vector<int> cnt, int pz, int lim) {
if (cur == ed) {
return cnt == vector<int>({0, 0, 0, 0});
}
int &fv = f[ed - cur][cnt[0]][cnt[1]][cnt[2]][cnt[3]];
if (!pz && !lim && fv != -1) return fv;
int ans = 0;
int vr = lim ? *cur - '0' : 9;
for (int i = 0; i <= vr; ++i) {
ans += Dp(next(cur), ed, Dec(cnt, i, pz), pz && i == 0, lim && i == vr);
}
ans %= p;
if (!pz && !lim) fv = ans;
return ans;
}
signed main() {
memset(f, -1, sizeof f);
int k;
string L, R;
cin >> k >> L >> R;
vector<int> cnt(4);
{
int tk = k;
for (int i = 0; i < 4; ++i) {
while (tk % pri[i] == 0) tk /= pri[i], ++cnt[i];
}
if (tk > 1) { cout << 0 << endl; return 0; }
}
int ans = Dp(R.begin(), R.end(), cnt, 1, 1);
cout << ans << endl;
ans -= Dp(L.begin(), L.end(), cnt, 1, 1);
{
int tk = k;
for (auto c : L) tk = tk / __gcd(k, (int)(c - '0'));
if (tk == 1) ++ans;
}
ans = (ans % p + p) % p;
cout << ans << endl;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 494964kb
input:
4 13 15 5 8 6 14 3 7
output:
12 1
result:
wrong answer 1st lines differ - expected: '2', found: '12'