QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327913 | #7881. Computational Complexity | Hunster | WA | 54ms | 9016kb | C++14 | 1.4kb | 2024-02-15 15:30:04 | 2024-02-15 15:30:05 |
Judging History
answer
#include <bits/stdc++.h>
using LL = long long;
constexpr int h[] = {2, 3, 5, 7};
constexpr LL M = (LL)(1e15) + 15;
int f0, g0, T; LL mod;
std::vector<LL> vals, f, g;
void dfs(int i, LL v) {
if (i == 4) {
vals.push_back(v);
return;
}
for (int j = 0; v < M; j++, v *= h[i])
dfs(i + 1, v);
}
LL query_f(LL v) {
int p = std::upper_bound(vals.begin(), vals.end(), v) - vals.begin() - 1;
return f[p];
}
LL query_g(LL v) {
int p = std::upper_bound(vals.begin(), vals.end(), v) - vals.begin() - 1;
return g[p];
}
int main() {
scanf("%d%d%d%lld", &f0, &g0, &T, &mod);
vals.push_back(0);
for (int i = 1; i <= 13; i++) dfs(0, i);
std::sort(vals.begin(), vals.end());
vals.resize(std::unique(vals.begin(), vals.end()) - vals.begin());
f.resize(vals.size());
g.resize(vals.size());
f[0] = f0;
g[0] = g0;
for (int i = 1; i < vals.size(); i++) {
LL t = vals[i];
f[i] = (query_g(t / 2) + query_g(t / 3) + query_g(t / 5) + query_g(t / 7)) % mod;
g[i] = (query_f(t / 2) + query_f(t / 3) + query_f(t / 4) + query_f(t / 5)) % mod;
if (t <= 13) {
f[i] = std::max(f[i], t);
g[i] = std::max(g[i], t);
}
}
while (T--) {
LL n;
scanf("%lld", &n);
printf("%lld %lld\n", query_f(n) % mod, query_g(n) % mod);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 50ms
memory: 9016kb
input:
1958 920 10 100000000000 0 1 2 3 10 100 200 1000 19580920 20232023
output:
1958 920 3680 7832 10592 9554 17504 11276 50294 64826 784112 893714 1894550 1905470 12057866 12979424 71481494756 48626708512 28127864908 7251681354
result:
ok 20 numbers
Test #2:
score: 0
Accepted
time: 54ms
memory: 8748kb
input:
0 0 10 100000000000 0 1 2 3 4 10 20 30 40 100
output:
0 0 1 1 2 2 3 3 4 4 11 12 25 26 41 41 55 58 162 172
result:
ok 20 numbers
Test #3:
score: -100
Wrong Answer
time: 53ms
memory: 8388kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 7 7 7 8 9 9 10
result:
wrong answer 3rd numbers differ - expected: '0', found: '1'