Submission #526891

# Submission time Handle Problem Language Result Execution time Memory
526891 2022-02-16T14:35:44 Z tphuc2908 Kangaroo (CEOI16_kangaroo) C++14
6 / 100
1 ms 332 KB
#include<bits/stdc++.h>

using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define ci(x) int x; cin>> x
#define TC(t) ci(t); while(t--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define cii(x, y) ci(x); ci(y)
#define ciii(x, y, z) ci(x); ci(y); ci(z)
#define mp make_pair
//#define int long long
typedef long long ll;
typedef vector<int> vi;
const int N = 2e3 + 5;
const int NN = 16 + 15;
const int mod = 998244353;
const int mod1 = 1e9 + 9;
const int pi = 31;
const int inf = 1e9 + 6;
const int block = 500;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

void readfile(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("text.inp", "r", stdin);
    #endif // ONLINE_JUDGE
//    freopen("connect.in", "r", stdin);
//    freopen("connect.out", "w", stdout);
}

int n, s, t;

void inp(){
    cin >> n >> s >> t;
}

int dp[N][N];

int add(int x, int y){
    x += y;
    while(x >= mod) x -= mod;
    while(x < 0) x += mod;
    return x;
}

int mul(int x, int y){
    return (x * 1LL * y) % mod;
}

void process(){
    dp[0][0] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= i; ++j){
            if(i+1==s || i+1==t){
                dp[i+1][j] = add(dp[i+1][j], dp[i][j]); // add vo component dau tien
                dp[i+1][j+1] = add(dp[i+1][j+1], dp[i][j]); // tao mot component moi ben trai cung
            }
            else{
                if(i + 1 < s && i + 1 < t){
                    dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], j + 1)); // tao mot component moi, co j + 1 vi tri
                    if(j) dp[i+1][j-1] = add(dp[i+1][j-1], mul(dp[i][j], j-1)); // co j - 1 vi tri de merge
                }
                else if((i + 1 >= t && i + 1 < s) || (i + 1 >= s && i + 1 < t)){
                        dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], j)); // tao mot component moi khong duoc o ben trai cung || phai cung, co j vi tri
                        if(j) dp[i+1][j-1] = add(dp[i+1][j-1], mul(dp[i][j], j-1)); // co j - 1 vi tri de merge
                    }
                    else{
                        dp[i+1][j+1] = add(dp[i+1][j+1], mul(dp[i][j], j-1)); // tao mot component moi khong duoc o ben trai cung && phai cung, co j - 1 vi tri
                        if(j) dp[i+1][j-1] = add(dp[i+1][j-1], mul(dp[i][j], j-1)); // co j - 1 vi tri de merge
                    }
            }
        }
    }
    cout << dp[n][1];
}

int main() {
//    readfile();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    TC(t){
        inp();
        process();
//        reset();
//    }
    return 0;
}

Compilation message

kangaroo.cpp: In function 'void readfile()':
kangaroo.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -