QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741215 | #7953. Product Delivery | yuto1115# | WA | 0ms | 4000kb | C++20 | 2.0kb | 2024-11-13 13:49:36 | 2024-11-13 13:49:36 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
const int md = 1000000007;
inline int add(int a, int b) {
return a + b < md ? a + b : a + b - md;
}
inline int sub(int a, int b) {
return a - b < 0 ? a - b + md : a - b;
}
inline int mul(int a, int b) {
return (long long)a * b % md;
}
const int N = 23;
long long k;
int num = 0;
char l[N], r[N];
std::map<long long, int> repr;
std::vector<std::vector<int> > dp;
std::vector<long long> back;
void build(long long k, int i = 2) {
if (i == 8) return;
printf("build %lld %d\n", k, i);
build(k, i + 1);
while (!(k % i)) {
k /= i;
repr[k] = num++;
back.push_back(k);
build(k, i + 1);
}
}
long long f(char *s, bool isr) {
int len, ans = 0;
for (len = 1; s[len]; ++len) {
ans = add(ans, dp[len][0]);
}
long long kk = k;
printf("running %s\n", s);
for (int i = 0; i < len; ++i) {
int dig = s[i] - '0';
for (int j = 0 + (bool)i; j < dig; ++j) {
long long g = std::__gcd((long long)j, kk);
printf("j is %d\n", j);
printf("g is %lld\n", g);
printf("adding %d %d\n", len - i - 1, repr[kk / g]);
ans = add(ans, dp[len - i - 1][g == 0 ? repr[1] : repr[kk / g]]);
printf("added\n");
}
if (!dig) kk = 1;
else {
long long g = std::__gcd((long long)dig, kk);
kk /= dig;
}
}
printf("HERE\n");
if (kk == 1 && isr) ans = add(ans, 1);
printf("returning %d\n", ans);
return ans;
}
int main() {
scanf("%lld%s%s", &k, l, r);
repr[k] = 0;
back.push_back(k);
++num;
build(k);
printf("back %d\n", (int)back.size());
printf("back k %lld\n", back[k]);
for (int len = 0; len < N; ++len) {
dp.push_back(std::vector<int>(back.size()));
if (len == 0) {
dp[0][repr[1]] = 1;
continue;
}
for (int i = 0; i < (int)back.size(); ++i) {
long long val = back[i];
for (int j = 0; j < 10; ++j) {
long long g = std::__gcd((long long)j, val);
dp[len][i] = add(dp[len][i], dp[len - 1][g == 0 ? repr[1] : repr[val / g]]);
}
printf("%d %d : %d\n", len, i, dp[len][i]);
}
}
printf("%d\n", sub(f(r, 1), f(l, 0)));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4000kb
input:
4 13 15 5 8 6 14 3 7
output:
build 4 2 build 4 3 build 4 4 build 4 5 build 4 6 build 4 7 build 1 5 build 1 6 build 1 7 build 2 3 build 2 4 build 2 5 build 2 6 build 2 7 build 1 3 build 1 4 build 1 5 build 1 6 build 1 7 back 4 back k 0 1 0 : 3 1 1 : 10 1 2 : 5 1 3 : 10 2 0 : 55 2 1 : 100 2 2 : 75 2 3 : 100 3 0 : 725 3 1 : 1000 3...
result:
wrong answer 1st lines differ - expected: '2', found: 'build 4 2'