이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O1")
#define int long long
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
using namespace std;
const int MAXN = 3e3+10;
const double SMALL = 1e-6;
const int INF = 5e5+10;
const int MX = 2e12;
const int MOD = 998244353;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;
int sum(int a, int b){
return (a+b)%MOD;
}
int mul(int a, int b){
return (a*b)%MOD;
}
int dp[MAXN][MAXN][4]; // dp[id][cc]
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, S, T; cin >> n >> S >> T;
dp[0][0][0] = 1;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(i==S || i==T){
for(int k=0; k<=1; k++){
dp[i][j][k+1] = sum(dp[i-1][j-1][k], dp[i][j][k+1]);
dp[i][j][k+1] = sum(dp[i-1][j][k], dp[i][j][k+1]);
}
continue;
}
for(int k=0; k<=2; k++){
dp[i][j][k] = sum(mul(dp[i-1][j-1][k], j-k), dp[i][j][k]);
//dp[i][j][k] = sum(mul(dp[i-1][j][k], mul(2, j)-k), dp[i][j][k]);
dp[i][j][k] = sum(mul(dp[i-1][j+1][k], j), dp[i][j][k]);
}
}
}
cout << dp[n][1][2]+dp[n][1][1]+dp[n][1][0] << '\n';
//cout << dp[n][1][2] << ' ' << dp[n][1][1] << ' ' <<dp[n][1][0] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |