QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328405#7881. Computational ComplexitywcyQwQWA 407ms54184kbC++142.2kb2024-02-15 19:57:522024-02-15 19:57:52

Judging History

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

  • [2024-02-15 19:57:52]
  • 评测
  • 测评结果:WA
  • 用时:407ms
  • 内存:54184kb
  • [2024-02-15 19:57:52]
  • 提交

answer

#include <bits/stdc++.h>
#define L(i, j, k) for (int i = (j); i <= (k); i++)
#define R(i, j, k) for (int i = (j); i >= (k); i--)

using namespace std;
using LL = long long;

const int N = 15, M = 1e6 + 10;
const LL V = 1e15;
LL f[N], g[N], mod;
int T;
map<LL, LL> dF, dG;
map<LL, int> cc;

template<class T = int> T read() {
    T x = 0, y = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') {
            y = -1;
        }
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * y;
}

void push(LL cur, vector<LL> &v) {
    if (cc[cur]) {
        return;
    }
    cc[cur] = 1;
    if (cur >= 14) {
        v.emplace_back(cur);
    }
    for (int p : {2, 3, 5, 7}) {
        if (cur <= V / p) {
            push(cur * p, v);
        }
    }
}

int main() {
    f[0] = read(), g[0] = read(), T = read();
    mod = read<LL>();
    L(i, 1, 13) {
        f[i] = max((LL)i, g[i / 2] + g[i / 3] + g[i / 5] + g[i / 7]);
        g[i] = max((LL)i, f[i / 2] + f[i / 3] + f[i / 4] + f[i / 5]);
        dF[i] = (f[i] - f[i - 1]) % mod;
        dG[i] = (g[i] - g[i - 1]) % mod;
    }
    vector<LL> vec;
    push(1, vec);
    push(11, vec);
    push(13, vec);
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    for (int p : vec) {
        dF[p] = (LL)(!(p % 2) * dG[p / 2] + !(p % 3) * dG[p / 3] + !(p % 5) * dG[p / 5] + !(p % 7) * dG[p / 7]) % mod;
        dG[p] = (LL)(!(p % 2) * dF[p / 2] + !(p % 3) * dF[p / 3] + !(p % 4) * dF[p / 4] + !(p % 5) * dF[p / 5]) % mod;
    }
    int cnt = 0;
    vector<pair<LL, LL>> F, G;
    F.push_back({0, f[0]});
    G.push_back({0, g[0]});
    for (auto t : dF) {
        F.push_back(t);
    }
    for (auto t : dG) {
        G.push_back(t);
    }
    L(i, 1, (int)F.size() - 1) {
        (F[i].second += F[i - 1].second) %= mod;
        (G[i].second += G[i - 1].second) %= mod;
    }
    while (T--) {
        LL m = read<LL>();
        printf("%lld %lld\n", (*--upper_bound(F.begin(), F.end(), make_pair(m, 0ll))).second, (*--upper_bound(G.begin(), G.end(), make_pair(m, 0ll))).second);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 407ms
memory: 54184kb

input:

1958 920 10 100000000000
0
1
2
3
10
100
200
1000
19580920
20232023

output:

1958 920
1958 920
3680 7832
10592 9554
46850 51002
766868 848798
1815098 1846778
11968130 12820520
71481494756 48626708512
28127864908 7251681354

result:

wrong answer 3rd numbers differ - expected: '3680', found: '1958'