QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#273395#7881. Computational Complexityucup-team2796#WA 12ms34464kbC++171.6kb2023-12-02 23:37:132023-12-02 23:37:14

Judging History

This is the latest submission verdict.

  • [2023-12-02 23:37:14]
  • Judged
  • Verdict: WA
  • Time: 12ms
  • Memory: 34464kb
  • [2023-12-02 23:37:13]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

typedef pair<long long, long long> PP;

vector<PP> F(1000000, {0,0}), G(1000000, {0,0});
long long M;

PP SUM(PP A, PP B, PP C, PP D) {
    PP X;
    X.first = A.first + B.first + C.first + D.first;
    X.second = A.second + B.second + C.second + D.second;
    X.first += X.second / M;
    X.second %= M;
    return X;
}

PP MAX(PP A, PP B) {
    if (A.first < B.first) return B;
    else if (A.first > B.first) return A;
    if (A.second < B.second) return B;
    else return A;
}

PP Zero = {0LL, 0LL};

PP DFS(map<long long, PP>& mp1, map<long long, PP>& mp2, long long N, int i) {
    if (N < 1000000) {
        if (i == 0) return F[N];
        else return G[N];
    }
    PP P = {0LL, N};
    if (i == 0) {
        if (mp1[N] != Zero) return mp1[N];
        else return mp1[N] = MAX(P, SUM(DFS(mp1, mp2, N/2, 1), DFS(mp1, mp2,N/3,1), DFS(mp1,mp2,N/5,1), DFS(mp1,mp2,N/7,1)));
    }
    else {
        if (mp2[N] != Zero) return mp2[N];
        else return mp2[N] = MAX(P, SUM(DFS(mp1, mp2, N/2, 0), DFS(mp1, mp2,N/3,0),DFS(mp1,mp2,N/4,0),DFS(mp1,mp2,N/5,0)));
    }
}

int main() {
    int T;
    cin >> F[0].second >> G[0].second >> T >> M;
    for (long long i = 1; i < 1000000; i++) {
        F[i] = MAX({0, i}, SUM(G[i/2],G[i/3],G[i/5],G[i/7]));
        G[i] = MAX({0, i}, SUM(F[i/2],F[i/3],F[i/4],F[i/5]));
    }
    for (int i = 0; i < T; i++) {
        long long X;
        cin >> X;
        map<long long, PP> mp1, mp2;
        cout << DFS(mp1, mp2, X, 0).second << ' ' << DFS(mp1, mp2, X, 1).second << endl;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 34300kb

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: 12ms
memory: 34384kb

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: 12ms
memory: 34464kb

input:

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

output:

2023 2023
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

result:

wrong answer 1st numbers differ - expected: '0', found: '2023'