QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297326#7766. 栞OccDreamer100 ✓24ms4668kbC++141.4kb2024-01-04 10:54:472024-01-04 10:54:47

Judging History

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

  • [2024-01-04 10:54:47]
  • 评测
  • 测评结果:100
  • 用时:24ms
  • 内存:4668kb
  • [2024-01-04 10:54:47]
  • 提交

answer

//code by Nobody.Emissary
#include<bits/stdc++.h>

using namespace std;

const int MAXN = 505;
const int mod = 998244353;

int n, k, q[MAXN], p[MAXN];
int f[MAXN][MAXN], g[MAXN], fac[MAXN];

inline void prework(int lim){
	fac[0]=1;
	for(int i=1;i<=lim;++i) fac[i]=1ll*fac[i-1]*i%mod;
	g[1]=1;
	for(int i=2;i<=n;++i){
		g[i]=fac[i];
		for(int j=1;j<i;++j) (g[i]+=mod-1ll*g[j]*fac[i-j]%mod)%=mod;
	}
	return ;
}

inline bool check(int l, int r){
	for(int i=l+1;i<=r;++i) if(p[i]<p[i-1]) return 0;
	return 1;
}

inline void solve(){
	f[1][1]=1;
	for(int i=2;i<=n;++i){
		if(q[i]<q[i-1]) break;
		f[i][1]=g[i];
	}
	for(int i=1;i<=n;++i){
		int v=q[i]; p[i]=v; q[i]=0;
		for(int j=1;j<=min(i,k-1);++j){
			int limpos=n-(k-j)+1, now=0;
			for(int o=i+1;o<=limpos;++o){
				now+=q[o]<v;
				if(now>1 || q[o]<q[o-1]) break;
				if(now && o<limpos) continue;
				if(now) (f[o][j+1]+=1ll*f[i][j]*fac[o-i-1]%mod)%=mod;
				else (f[o][j+1]+=1ll*f[i][j]*g[o-i]%mod)%=mod;
			}
		}
	}
	f[0][0]=1; int ans=0;
	for(int i=0;i<n;++i)
		if(check(i+1,n)){
			if(i+2<=n && p[i+1]<p[i] && p[i+2]<p[i]) continue;
			if(p[i+1]>p[i]) (ans+=1ll*f[i][k-1]*fac[n-i]%mod)%=mod;
			else (ans+=1ll*f[i][k-1]*fac[n-i-1]%mod)%=mod;	
		}
	cout << ans << endl;
	return ;
}

int main(){
	cin >> n >> k;
	for(int i=1;i<=n;++i) cin >> q[i];
	prework(n); solve();
	return 0;
}
/*
6 3
1 2 5 3 4 6
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3592kb

input:

6 1
1 2 3 4 5 6

output:

720

result:

ok 1 number(s): "720"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

6 3
1 2 5 3 4 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

6 3
1 2 4 3 6 5

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

6 5
1 2 3 5 4 6

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

6 5
1 2 3 5 4 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

6 4
1 3 2 4 6 5

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

6 5
1 3 2 5 4 6

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

6 3
1 2 3 6 5 4

output:

13

result:

ok 1 number(s): "13"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

6 4
1 2 5 4 3 6

output:

3

result:

ok 1 number(s): "3"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

6 3
1 2 5 4 3 6

output:

0

result:

ok 1 number(s): "0"

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #11:

score: 20
Accepted
time: 0ms
memory: 3696kb

input:

9 9
1 2 3 4 5 6 7 8 9

output:

1

result:

ok 1 number(s): "1"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

9 3
1 2 3 4 5 6 9 7 8

output:

3447

result:

ok 1 number(s): "3447"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

9 7
1 3 2 4 6 5 7 8 9

output:

3

result:

ok 1 number(s): "3"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

9 5
1 2 3 4 5 6 7 9 8

output:

531

result:

ok 1 number(s): "531"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

9 9
1 4 3 2 5 6 7 8 9

output:

1

result:

ok 1 number(s): "1"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

9 2
1 2 3 4 5 6 7 9 8

output:

29093

result:

ok 1 number(s): "29093"

Test #17:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

9 4
1 2 3 4 5 6 7 9 8

output:

2109

result:

ok 1 number(s): "2109"

Test #18:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

9 8
1 2 3 5 4 7 6 8 9

output:

4

result:

ok 1 number(s): "4"

Test #19:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

9 7
1 2 3 4 5 7 6 9 8

output:

23

result:

ok 1 number(s): "23"

Test #20:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

9 7
1 2 3 4 5 7 6 9 8

output:

23

result:

ok 1 number(s): "23"

Subtask #3:

score: 30
Accepted

Test #21:

score: 30
Accepted
time: 10ms
memory: 4484kb

input:

500 369
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

151242732

result:

ok 1 number(s): "151242732"

Test #22:

score: 0
Accepted
time: 21ms
memory: 4560kb

input:

500 261
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

175105582

result:

ok 1 number(s): "175105582"

Test #23:

score: 0
Accepted
time: 19ms
memory: 4604kb

input:

500 79
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

328555836

result:

ok 1 number(s): "328555836"

Test #24:

score: 0
Accepted
time: 17ms
memory: 4472kb

input:

500 306
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

738246233

result:

ok 1 number(s): "738246233"

Test #25:

score: 0
Accepted
time: 14ms
memory: 4668kb

input:

500 291
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

90157368

result:

ok 1 number(s): "90157368"

Test #26:

score: 0
Accepted
time: 20ms
memory: 4468kb

input:

500 268
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

582110163

result:

ok 1 number(s): "582110163"

Test #27:

score: 0
Accepted
time: 14ms
memory: 4496kb

input:

500 295
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

551109392

result:

ok 1 number(s): "551109392"

Test #28:

score: 0
Accepted
time: 24ms
memory: 4468kb

input:

500 137
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

709320534

result:

ok 1 number(s): "709320534"

Test #29:

score: 0
Accepted
time: 18ms
memory: 4664kb

input:

500 66
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

735053639

result:

ok 1 number(s): "735053639"

Test #30:

score: 0
Accepted
time: 23ms
memory: 4468kb

input:

500 233
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

676167049

result:

ok 1 number(s): "676167049"

Subtask #4:

score: 40
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #31:

score: 40
Accepted
time: 22ms
memory: 4500kb

input:

500 198
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

830163792

result:

ok 1 number(s): "830163792"

Test #32:

score: 0
Accepted
time: 4ms
memory: 4612kb

input:

500 432
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 80 78 79 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

409343845

result:

ok 1 number(s): "409343845"

Test #33:

score: 0
Accepted
time: 15ms
memory: 4552kb

input:

500 265
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

194041644

result:

ok 1 number(s): "194041644"

Test #34:

score: 0
Accepted
time: 24ms
memory: 4604kb

input:

500 173
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

526227080

result:

ok 1 number(s): "526227080"

Test #35:

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

input:

500 483
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

614441401

result:

ok 1 number(s): "614441401"

Test #36:

score: 0
Accepted
time: 16ms
memory: 4664kb

input:

500 243
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

284882224

result:

ok 1 number(s): "284882224"

Test #37:

score: 0
Accepted
time: 12ms
memory: 4596kb

input:

500 282
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

308933889

result:

ok 1 number(s): "308933889"

Test #38:

score: 0
Accepted
time: 11ms
memory: 4668kb

input:

500 231
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

131213230

result:

ok 1 number(s): "131213230"

Test #39:

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

input:

500 415
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 100 99 ...

output:

590026968

result:

ok 1 number(s): "590026968"

Test #40:

score: 0
Accepted
time: 7ms
memory: 4548kb

input:

500 344
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

124432123

result:

ok 1 number(s): "124432123"