QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#846168#9916. Defeat the EnemiesZawosWA 442ms18772kbC++202.9kb2025-01-06 22:45:002025-01-06 22:45:01

Judging History

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

  • [2025-01-06 22:45:01]
  • 评测
  • 测评结果:WA
  • 用时:442ms
  • 内存:18772kb
  • [2025-01-06 22:45:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef map<ll,ll> mll;
typedef vector<int> vi;
typedef set<ll> sll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
ll gcd(ll a, ll b) {return a == 0? b: gcd(b%a,a);}
ll lcm(ll a, ll b) {return a * (b / gcd(a,b));}
#define inf 1e17
#define pb(x) push_back(x)
#define rep(i, x,n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define fo(x) find_by_order(x)
#define ok(x) order_of_key(x)
const ll mod = 998244353;
const int M = 1e4;
const int K = 15;
int lg[M + 1];
pll dp2[M + 1];

struct sparseTable {
    vector<vi> st;
    void build(vi &nums){
        int n = nums.size();
 
        st.resize(K + 1, vi(n));
 
        st[0] = nums;
 
        for (int i = 1; i <= K; i++)
            for (int j = 0; j + (1 << i) <= n; j++)
                st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
    }
 
    int query(int L, int R){
        int i = lg[R - L + 1];
        return max(st[i][L], st[i][R - (1 << i) + 1]);
    }
};

map<ii, pll> dp;

pll g(int Y, vll &cost) {
    if (Y == 0) return {0, 1};
    if (dp2[Y].first != -1) return dp2[Y];
    pll res = {1e18, 0};
    rep(i, 1, cost.size()) {
        pll tran = g(max(0, Y - i), cost);
        tran.first += cost[i];
        if (tran.first < res.first)
            res = tran;
        else if (tran.first == res.first)
            res.second = (res.second + tran.second) % mod;
    }
    return dp2[Y] = res;
}

pll f(int X, int Y, vll &cost, sparseTable &st, int mx) {
    if (X >= mx) return g(Y, cost);
    if (dp.count({X, Y})) return dp[{X, Y}];
    pll res = {INT_MAX, 0};
    rep(i, 1, cost.size()) {
        int broken = st.query(X + 1, min(X + i, mx));
        pll tran = f(X + i, max({0, Y - i, broken}), cost, st, mx);
        tran.first += cost[i];
        if (tran.first < res.first) {
            res = tran;
        }else if (res.first == tran.first) {
            res.second = (res.second + tran.second) % mod;
        }
    }

    return dp[{X, Y}] = res;
}

void solve() {
    int n, m; cin >> n >> m;
    dp.clear();
    rep(i, 0, m + 1)
        dp2[i] = {-1, -1};
     
    vi health(m + 1);

    vi A(n), B(n);
    rep(i, 0, n) cin >> A[i];
    rep(i, 0, n) cin >> B[i];

    rep(i, 0, n) {
        health[B[i]] = max(health[B[i]], A[i]);
    }

    sparseTable st; st.build(health);

    int k; cin >> k;
    vll cost(k + 1);
    rep(i, 1, k + 1) cin >> cost[i];
    ii res = f(0, 0, cost, st, *max_element(all(B)));
    cout << res.first << " " << res.second << "\n";
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    lg[1] = 0;
    for (int i = 2; i <= M; i++)
        lg[i] = lg[i/2] + 1;
    int t = 1; cin >> t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3944kb

input:

4
5 5
3 5 2 1 2
3 1 3 2 3
3
2 3 4
3 2
2 2 2
2 2 2
3
2 3 3
7 6
5 3 4 6 6 3 4
4 6 4 2 3 5 5
4
2 4 6 7
10 100
38 49 79 66 49 89 21 55 13 23
67 56 26 39 56 16 84 50 92 82
11
6 6 7 8 9 9 9 9 9 9 9

output:

9 1
6 4
18 18
99 44387

result:

ok 8 numbers

Test #2:

score: 0
Accepted
time: 2ms
memory: 3892kb

input:

1000
5 3
1 1 3 1 2
3 2 1 1 2
1
5
5 3
3 3 2 2 1
1 1 3 1 1
3
3 1 3
5 5
4 3 5 1 4
5 5 2 5 5
2
1 5
5 5
5 5 5 5 4
2 1 2 4 1
2
1 1
5 3
2 1 2 1 1
1 3 2 1 1
1
5
2 1
1 1
1 1
3
2 2 1
5 5
2 3 5 2 2
5 2 4 3 1
2
3 3
5 1
1 1 1 1 1
1 1 1 1 1
3
5 4 4
5 4
1 4 4 4 2
4 3 1 3 3
1
2
1 5
2
2
3
4 2 4
1 5
4
5
1
4
2 5
1 5
1...

output:

20 1
3 1
9 1
5 4
20 1
2 1
15 4
8 4
14 1
4 1
36 1
12 1
27 1
2 1
20 1
4 1
10 1
23 1
10 1
4 1
28 1
4 1
5 1
4 1
6 1
8 1
6 1
16 1
9 6
5 1
30 1
4 1
4 1
2 1
35 1
10 1
2 1
4 1
15 6
4 1
20 1
4 1
6 1
40 1
4 1
18 1
8 1
7 1
6 1
2 1
10 1
3 1
9 1
8 1
4 1
6 4
20 1
8 2
10 1
2 1
2 1
50 1
24 1
6 1
10 16
10 1
6 1
3 1
...

result:

ok 2000 numbers

Test #3:

score: 0
Accepted
time: 5ms
memory: 3912kb

input:

200
50 16
15 15 15 14 15 13 15 15 14 15 16 16 16 12 16 16 16 16 14 13 14 16 13 16 13 16 14 13 16 16 12 14 16 15 13 16 14 16 12 15 14 15 13 14 15 15 15 15 16 13
13 14 16 13 16 16 16 15 13 15 13 16 15 15 16 16 16 16 16 15 16 16 14 12 15 16 16 16 13 12 15 15 16 12 15 14 16 16 16 12 16 16 16 16 15 14 15...

output:

14 6889
68 33856
60 841
388 14400
20 214369
100 1
72 8281
6 256
39 30
4 1
58 1
12 144
4 144
116 169
46 38416
100 1
26 11025
88 36
80 1
10 81
114 100
92 413318192
56 1
50 1296
400 481524050
68 1
32 9
6 1
1100 1
100 103437186
46 1600
80 57
44 576
92 1
26 441
7 320
106 9
68 29241
34 324
29 7878
4 1
4 1...

result:

ok 400 numbers

Test #4:

score: -100
Wrong Answer
time: 442ms
memory: 18772kb

input:

1
500000 10000
3544 1546 5208 6621 759 9303 9198 8910 9046 2355 5960 2034 7059 8504 4449 9573 3020 7106 6973 2021 5158 6148 386 3559 5050 9264 9497 2912 1170 7698 4529 4172 7729 3382 7613 3770 6552 2365 2193 9581 146 7853 5384 4589 3369 3102 9585 3124 1886 8301 8125 3842 4101 5388 3571 10 7190 2464 ...

output:

2147483647 0

result:

wrong answer 1st numbers differ - expected: '22388256114', found: '2147483647'