QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47177#4623. Matryoshka DollYeruihuaAC ✓181ms199200kbC++931b2022-09-04 15:09:252022-09-04 15:09:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-04 15:09:25]
  • 评测
  • 测评结果:AC
  • 用时:181ms
  • 内存:199200kb
  • [2022-09-04 15:09:25]
  • 提交

answer

#include <bits/stdc++.h>
#define N  5005
#define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define mod 998244353
#define ll long long
using namespace std;

ll dp[N][N];
ll a[N];
ll cnt[N];
int T,n;

int main()
{
    IO;
    cin>>T;
    while(T--){
        int r,k;
        cin>>n>>k>>r;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        int nowp=0;
        for(int i=1; i<=n; i++){
            while(a[nowp+1]+r<=a[i])   nowp++;
            cnt[i] = nowp;
        }
        dp[0][0] = 1;
        for(int i=1; i<=n; i++){
            for(int j=i-cnt[i]; j<=k; j++){
                dp[i][j] = (dp[i-1][j-1] + 1LL * dp[i-1][j] * (j-(i-cnt[i]-1)))% mod;
            }
        }
        cout<<dp[n][k]<<endl;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=k; j++){
                dp[i][j] = 0;
            }
        }
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 181ms
memory: 199200kb

input:

20
4 3 2
1 2 3 4
4 2 1
1 1 2 2
10 3 5
7 20 27 27 34 36 40 56 63 98
10 5 10
5 6 11 20 34 39 42 57 86 99
100 2 4
61 139 210 338 426 591 614 637 658 678 699 1002 1015 1162 1424 1433 1502 1756 1994 2073 2164 2189 2258 2305 2460 2464 2497 2507 2512 2526 2557 2742 2794 2809 3060 3075 3201 3226 3380 3576 3...

output:

3
2
2852
10554
719747106
690165012
206258543
359242369
612315029
205154325
247697612
404757277
1
927604200
0
366237347
948502315
1
119095265
1

result:

ok 20 lines