QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#846107#9916. Defeat the EnemiesZawosRE 2ms3992kbC++202.5kb2025-01-06 22:00:502025-01-06 22:00:51

Judging History

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

  • [2025-01-06 22:00:51]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3992kb
  • [2025-01-06 22:00:50]
  • 提交

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 = 100;
const int K = 20;
int lg[3 * 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]);
    }
};

pll dp[3 * M + 1][M + 1];

pll f(int X, int Y, vll &cost, sparseTable &st, int mx) {
    if (X >= mx && Y == 0) return {0, 1};
    if (dp[X][Y].first != -1) return dp[X][Y];
    pll res = {1e18, 0};
    rep(i, 1, cost.size()) {
        int broken = st.query(X + 1, X + i);
        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;
    rep(i, 0, 3 * m + 1)
    rep(j, 0, m + 1)
        dp[i][j] = {-1, -1};
    
    vi health(3 * 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];

    pll 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 <= 3 * 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: 3992kb

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: 3876kb

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: -100
Runtime Error

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:


result: