QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866851#9916. Defeat the EnemiesmanizareRE 36ms8168kbC++202.1kb2025-01-22 20:05:022025-01-22 20:05:03

Judging History

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

  • [2025-01-22 20:05:03]
  • 评测
  • 测评结果:RE
  • 用时:36ms
  • 内存:8168kb
  • [2025-01-22 20:05:02]
  • 提交

answer

    #include <bits/stdc++.h> 
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define pii pair<int,int> 
#define all(a) a.begin(),a.end()
#define S second 
#define sz(a) (int)a.size()
#define rep(i , a , b) for(int i = (a) ; i <= (b) ; i++)
#define per(i , a , b) for(int i = (a) ; i >= (b) ; i--)
#define ld long double
#define int long long 
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 5e5+20 , maxm = 2e4 + 10, sq = 500 , inf = 1e18+10 , mod =998244353 ; 
int a[maxn] ,b[maxn] , x[maxm]  , c[200];
pii dp[maxn][140] ;

inline void upd(pii &a , pii b , int c){
    b.F += c; 
    if(a.F > b.F){
        a = b;
    }else if(a.F == b.F){
        a.S += b.S ;
        if(a.S >= mod)a.S-= mod ; 
    }
}

signed main(){
    ios_base::sync_with_stdio(false) ; cin.tie(0) ;
    int T ;
    cin >> T ;
    while(T--){
        int n , m ;
        cin >> n >> m ; 
        rep(i ,1, n){
            cin >> b[i] ;
        }
        int sm =0 ;
        rep(i ,1, n){
            cin >> a[i] ;
            sm = max(sm , a[i]+b[i]) ;
        }
        int k ;
        cin>> k ; 
        rep( i,1 ,k){
            cin >> c[i] ;
        }
        rep(i ,1, sm+2*k){
            x[i] = inf; 
        }
        rep(i ,1 ,n){
            x[b[i]] = min(x[b[i]] , b[i] + (sm-a[i]-b[i])) ;
        }
        rep(i , 0, sm+2*k)rep(j , 0, k){
            dp[i][j] = {inf,0} ;
        }
        dp[0][0] = {0,1} ;
        rep(i , 0 ,sm+2*k){
            rep(j , 0 ,k){
                int mn = inf ;
                rep(z , 1 ,k){
                    upd(dp[i+z][max(j , i+z-mn)] , dp[i][j], c[z]) ;
                    mn= min(mn , x[i+z]);
                }
            }
        }
        pii ans ;
        ans = {inf , 0} ;
        rep(i , sm , sm+2*k){
            rep(j , 0 ,k){
                if(i-sm >= j){
                    upd(ans , dp[i][j] , 0);
                }
            }
        }
        cout << ans.F << " " << ans.S << "\n"; 
    }
}
/*
 
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8040kb

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: 1ms
memory: 7792kb

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: 36ms
memory: 8168kb

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

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:


result: