QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327939#7881. Computational ComplexityHunsterWA 86ms9740kbC++142.0kb2024-02-15 15:37:282024-02-15 15:37:29

Judging History

你现在查看的是最新测评结果

  • [2024-02-15 15:37:29]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:9740kb
  • [2024-02-15 15:37:28]
  • 提交

answer

#include <bits/stdc++.h>

using LL = long long;

constexpr LL inf64 = (LL)(1e18) + 18;
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, ef, eg;
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);
}
std::pair<LL, LL> query_f(LL v) {
    int p = std::upper_bound(vals.begin(), vals.end(), v) - vals.begin() - 1;
    return {f[p], ef[p]};
}
std::pair<LL, LL> query_g(LL v) {
    int p = std::upper_bound(vals.begin(), vals.end(), v) - vals.begin() - 1;
    return {g[p], eg[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());
    ef.resize(vals.size());
    g.resize(vals.size());
    eg.resize(vals.size());
    f[0] = f0 % mod;
    g[0] = g0 % mod;
    ef[0] = f0;
    eg[0] = g0;
    for (int i = 1; i < vals.size(); i++) {
        LL t = vals[i];
        f[i] = (query_g(t / 2).first + query_g(t / 3).first + query_g(t / 5).first + query_g(t / 7).first) % mod;
        ef[i] = std::min(inf64, query_g(t / 2).second + query_g(t / 3).second + query_g(t / 5).second + query_g(t / 7).second);
        g[i] = (query_f(t / 2).first + query_f(t / 3).first + query_f(t / 4).first + query_f(t / 5).first) % mod;
        eg[i] = std::min(inf64, query_f(t / 2).second + query_f(t / 3).second + query_f(t / 4).second + query_f(t / 5).second) % mod;
        if (ef[i] <= 13) {
            ef[i] = std::max(t, ef[i]);
            f[i] = ef[i] % mod;
        }
        if (eg[i] <= 13) {
            eg[i] = std::max(t, eg[i]);
            g[i] = eg[i] % mod;
        }
    }
    while (T--) {
        LL n;
        scanf("%lld", &n);
        printf("%lld %lld\n", query_f(n).first, query_g(n).first);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 86ms
memory: 9740kb

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: 85ms
memory: 8768kb

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: 86ms
memory: 8624kb

input:

2023 2023 10 2023
0
1
2
3
4
5
6
7
8
9

output:

0 0
0 1
1 2
2 3
3 4
4 5
6 6
7 7
8 8
9 9

result:

wrong answer 4th numbers differ - expected: '0', found: '1'