QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85918#5274. IQ Gamechenxinyang2006AC ✓14ms5132kbC++142.8kb2023-03-08 21:13:542023-03-08 21:13:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 21:13:57]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:5132kb
  • [2023-03-08 21:13:54]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define mpy(a,b) memcpy(a,b,sizeof(b))
#define dbg(...) cerr<<"#"<<__LINE__<<": "<<__VA_ARGS__<<endl
#define Fi(s) freopen(s,"r",stdin)
#define Fo(s) freopen(s,"w",stdout)
#define Fio(s) Fi(s".in"),Fo(s".out")
#define SZ(S) (int)S.size()
#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}

/*template <class T,class U>
inline void add(T &x,U y){
	x += y;
	if(x >= mod) x -= mod;
}

template <class T,class U>
inline void sub(T &x,U y){
	x -= y;
	if(x < 0) x += mod;
}*/

ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}
int m,n,s;
int q[205],a[205],b[205];
ll sum[205][205],C[205][205],fact[205],ifac[205];

ll dp[205][205],res[205][205];

int main(){
	scanf("%d%d%d",&m,&n,&s);
	int pos = -1;
	rep(i,1,n){
		scanf("%d",&q[i]);
		if(q[i] == s) pos = i;
		a[i] = q[i] - q[i - 1];
	}
	a[1] += m - q[n];
	assert(pos != -1);
	rep(i,pos + 1,n) b[i - pos] = a[i];
	rep(i,1,pos) b[i + n - pos] = a[i];

	rep(i,1,n){
		rep(j,i,n){
			sum[i][j] = (sum[i][j - 1] + b[j]) % mod;
		}
	}
//	rep(i,1,n) printf("%d ",b[i]);
//	printf("\n");
	ll in = power(m);
	rep(i,1,n){
		rep(j,i,n){
			sum[i][j] = sum[i][j] * in % mod;
		}
	}

	rep(i,0,n){
		C[i][0] = 1;
		rep(j,1,i) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
	}
	fact[0] = 1;
	rep(i,1,n) fact[i] = fact[i - 1] * i % mod;
	ifac[n] = power(fact[n]);
	per(i,n - 1,0) ifac[i] = ifac[i + 1] * (i + 1) % mod;

	rep(i,1,n) dp[i][i] = 1;
	rep(len,2,n){
		rep(i,1,n){
			int j = i + len - 1;
			if(j > n) break;
			rep(k,i,j - 1) dp[i][j] += sum[i][k] * dp[i][k] % mod * dp[k + 1][j] % mod * C[j - i - 1][k - i] % mod;
			dp[i][j] %= mod;
		}
	}

	rep(i,1,n){
		rep(j,i,n){
//			printf("range [%d,%d] %lld\n",i,j,dp[i][j]);
			dp[i][j] = dp[i][j] * ifac[j - i] % mod;
		}
	}
	res[0][0] = 1;
	rep(i,1,n){
		rep(j,1,i){
			rep(k,0,j - 1){
				res[i][k + i - j] += res[j - 1][k] * dp[j][i] % mod;
			}
		}
		rep(k,0,i - 1) res[i][k] %= mod;
	}
	ll ans = 0;
	rep(i,0,n) ans += res[n][i] * fact[i] % mod;
	printf("%lld\n",ans % mod);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3852kb

input:

3 2 3
2 3

output:

665496237

result:

ok 1 number(s): "665496237"

Test #2:

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

input:

6 3 4
1 2 4

output:

582309208

result:

ok 1 number(s): "582309208"

Test #3:

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

input:

8 8 5
1 2 3 4 5 6 7 8

output:

499122181

result:

ok 1 number(s): "499122181"

Test #4:

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

input:

1 1 1
1

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

2 1 2
2

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

2 2 1
1 2

output:

499122178

result:

ok 1 number(s): "499122178"

Test #7:

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

input:

3 1 2
2

output:

1

result:

ok 1 number(s): "1"

Test #8:

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

input:

3 2 3
1 3

output:

332748119

result:

ok 1 number(s): "332748119"

Test #9:

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

input:

3 3 1
1 2 3

output:

2

result:

ok 1 number(s): "2"

Test #10:

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

input:

3 3 3
1 2 3

output:

2

result:

ok 1 number(s): "2"

Test #11:

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

input:

4 1 4
4

output:

1

result:

ok 1 number(s): "1"

Test #12:

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

input:

4 2 4
2 4

output:

499122178

result:

ok 1 number(s): "499122178"

Test #13:

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

input:

4 3 3
2 3 4

output:

935854083

result:

ok 1 number(s): "935854083"

Test #14:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

4 4 1
1 2 3 4

output:

499122179

result:

ok 1 number(s): "499122179"

Test #15:

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

input:

4 4 4
1 2 3 4

output:

499122179

result:

ok 1 number(s): "499122179"

Test #16:

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

input:

5 1 4
4

output:

1

result:

ok 1 number(s): "1"

Test #17:

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

input:

5 3 4
2 3 4

output:

199648873

result:

ok 1 number(s): "199648873"

Test #18:

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

input:

5 5 3
1 2 3 4 5

output:

3

result:

ok 1 number(s): "3"

Test #19:

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

input:

10 2 3
3 10

output:

99824437

result:

ok 1 number(s): "99824437"

Test #20:

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

input:

10 6 10
2 5 6 7 8 10

output:

146103047

result:

ok 1 number(s): "146103047"

Test #21:

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

input:

10 9 4
1 2 3 4 5 7 8 9 10

output:

463868913

result:

ok 1 number(s): "463868913"

Test #22:

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

input:

50 3 37
8 37 49

output:

411276675

result:

ok 1 number(s): "411276675"

Test #23:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

50 10 13
1 13 20 27 28 32 34 35 49 50

output:

221421997

result:

ok 1 number(s): "221421997"

Test #24:

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

input:

50 25 12
1 4 5 10 11 12 14 16 19 21 22 27 28 29 30 31 33 34 37 38 39 45 47 49 50

output:

754768470

result:

ok 1 number(s): "754768470"

Test #25:

score: 0
Accepted
time: 1ms
memory: 4100kb

input:

50 40 22
2 3 4 5 6 7 8 12 13 14 15 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 37 39 40 41 42 43 45 46 47 50

output:

16385632

result:

ok 1 number(s): "16385632"

Test #26:

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

input:

50 49 29
1 2 3 4 5 6 7 8 9 10 11 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

output:

501281691

result:

ok 1 number(s): "501281691"

Test #27:

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

input:

200 1 28
28

output:

1

result:

ok 1 number(s): "1"

Test #28:

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

input:

200 2 66
66 143

output:

454201182

result:

ok 1 number(s): "454201182"

Test #29:

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

input:

200 2 133
107 133

output:

209631316

result:

ok 1 number(s): "209631316"

Test #30:

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

input:

200 5 96
60 86 96 121 130

output:

713590253

result:

ok 1 number(s): "713590253"

Test #31:

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

input:

200 14 89
3 7 30 42 54 64 80 82 89 105 133 160 176 184

output:

105441194

result:

ok 1 number(s): "105441194"

Test #32:

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

input:

200 42 152
4 9 17 20 35 40 43 49 52 71 74 76 81 83 85 92 93 97 98 104 111 113 124 132 134 139 140 141 144 148 149 151 152 153 157 164 172 181 192 195 199 200

output:

547988971

result:

ok 1 number(s): "547988971"

Test #33:

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

input:

200 132 98
2 3 6 7 8 15 16 17 18 20 22 23 26 27 28 30 31 32 34 35 36 38 39 41 44 45 46 48 50 53 54 55 56 57 58 59 60 61 64 68 69 72 73 76 77 78 79 81 82 83 84 85 86 87 88 89 92 95 96 97 98 100 102 103 104 105 106 107 108 109 110 112 114 115 116 119 120 121 122 123 124 125 127 130 131 133 134 135 136...

output:

697737806

result:

ok 1 number(s): "697737806"

Test #34:

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

input:

200 199 1
1 2 3 4 5 6 7 8 9 10 11 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:

544578651

result:

ok 1 number(s): "544578651"

Test #35:

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

input:

200 199 200
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 95 96 97 98 99 100...

output:

492091840

result:

ok 1 number(s): "492091840"

Test #36:

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

input:

200 200 1
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 10...

output:

499122277

result:

ok 1 number(s): "499122277"

Test #37:

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

input:

200 200 200
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 ...

output:

499122277

result:

ok 1 number(s): "499122277"

Test #38:

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

input:

1000000000 1 584008146
584008146

output:

1

result:

ok 1 number(s): "1"

Test #39:

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

input:

1000000000 2 143634686
143634686 490248799

output:

788008183

result:

ok 1 number(s): "788008183"

Test #40:

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

input:

1000000000 2 625148472
130787283 625148472

output:

708092867

result:

ok 1 number(s): "708092867"

Test #41:

score: 0
Accepted
time: 1ms
memory: 3884kb

input:

1000000000 5 151559002
95471916 151559002 583238649 818909076 923651296

output:

775804433

result:

ok 1 number(s): "775804433"

Test #42:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

1000000000 14 205525617
111116916 205525617 243011849 273099893 284288753 314909659 339014539 645710065 731239674 752446721 769648839 789762353 882826624 995895973

output:

450520152

result:

ok 1 number(s): "450520152"

Test #43:

score: 0
Accepted
time: 3ms
memory: 4100kb

input:

1000000000 42 865997896
6868421 39816218 63566993 91094555 107013042 108056448 117381010 121861189 126253576 133844271 182455123 218365482 248658016 276646670 300024164 316030537 324539893 348544216 360102712 385863758 404468357 431231451 447180169 494978380 518754701 520854460 567587770 581920139 6...

output:

164406954

result:

ok 1 number(s): "164406954"

Test #44:

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

input:

1000000000 132 818493345
7391593 16222676 16728141 21745953 29333193 31188659 38084625 45401834 45924061 51938800 55381065 58521522 58912656 66911881 68351994 83837784 88530233 91327734 108866516 113286389 118258521 149411552 154259554 172406123 196024798 216432936 222418757 224056724 228826957 2593...

output:

757383914

result:

ok 1 number(s): "757383914"

Test #45:

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

input:

1000000000 199 10681544
10681544 23177378 37659235 49989953 53393710 61018524 62698570 65610111 67123127 68465120 72989626 95514621 97942856 101745615 117638431 126271889 131429697 132191147 133615010 145840977 148017323 161280418 171542888 171760515 174439210 178859787 179544188 192118010 196229683...

output:

295777843

result:

ok 1 number(s): "295777843"

Test #46:

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

input:

1000000000 199 994808313
2707463 12344045 14140946 14857970 22582954 25580417 44389041 50691819 56661919 60680768 72527094 80573726 97445667 98167297 98446378 101716264 108638977 109355441 109691948 110735111 111017207 121934675 124220281 126079617 128591556 136313192 146221552 151218030 156276339 1...

output:

961385715

result:

ok 1 number(s): "961385715"

Test #47:

score: 0
Accepted
time: 8ms
memory: 5128kb

input:

1000000000 200 3890484
3890484 11749010 11906913 16835982 22023496 27364740 28762232 32696137 37856675 39468187 53690489 55784771 63468013 64027836 64213198 65294191 67142061 77567023 79511482 85199271 88155873 97619048 101110467 103270300 110903625 114541922 124852100 125270552 133660962 133815707 ...

output:

702683742

result:

ok 1 number(s): "702683742"

Test #48:

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

input:

1000000000 200 991106656
9679423 13244204 15575122 16413713 28107751 30390226 34027699 39891292 42578120 52517304 66319727 81066860 81486839 82624725 91168249 97765400 99154793 99372988 100307626 102763210 110009725 111808075 119865073 124641551 127902883 144016462 145656730 171445047 172859397 1771...

output:

430656495

result:

ok 1 number(s): "430656495"