QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85914 | #5274. IQ Game | chenxinyang2006 | WA | 2ms | 4008kb | C++14 | 2.8kb | 2023-03-08 21:12:16 | 2023-03-08 21:12:17 |
Judging History
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;
}
}
}
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: 3636kb
input:
3 2 3 2 3
output:
665496237
result:
ok 1 number(s): "665496237"
Test #2:
score: 0
Accepted
time: 1ms
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: 3636kb
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: 0ms
memory: 3600kb
input:
1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
2 1 2 2
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
2 2 1 1 2
output:
499122178
result:
ok 1 number(s): "499122178"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
3 1 2 2
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2ms
memory: 3660kb
input:
3 2 3 1 3
output:
332748119
result:
ok 1 number(s): "332748119"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
3 3 1 1 2 3
output:
2
result:
ok 1 number(s): "2"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
3 3 3 1 2 3
output:
2
result:
ok 1 number(s): "2"
Test #11:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
4 1 4 4
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
4 2 4 2 4
output:
499122178
result:
ok 1 number(s): "499122178"
Test #13:
score: 0
Accepted
time: 2ms
memory: 3668kb
input:
4 3 3 2 3 4
output:
935854083
result:
ok 1 number(s): "935854083"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
4 4 1 1 2 3 4
output:
499122179
result:
ok 1 number(s): "499122179"
Test #15:
score: 0
Accepted
time: 2ms
memory: 3600kb
input:
4 4 4 1 2 3 4
output:
499122179
result:
ok 1 number(s): "499122179"
Test #16:
score: 0
Accepted
time: 2ms
memory: 3660kb
input:
5 1 4 4
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
5 3 4 2 3 4
output:
199648873
result:
ok 1 number(s): "199648873"
Test #18:
score: 0
Accepted
time: 2ms
memory: 3880kb
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: 3584kb
input:
10 2 3 3 10
output:
99824437
result:
ok 1 number(s): "99824437"
Test #20:
score: 0
Accepted
time: 2ms
memory: 3580kb
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: 3900kb
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: 1ms
memory: 3624kb
input:
50 3 37 8 37 49
output:
411276675
result:
ok 1 number(s): "411276675"
Test #23:
score: 0
Accepted
time: 1ms
memory: 3648kb
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: -100
Wrong Answer
time: 2ms
memory: 4008kb
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:
462515504
result:
wrong answer 1st numbers differ - expected: '754768470', found: '462515504'