Problem:
Score : 800 points

Problem Statement

Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X.

Constraints

1 \leq N \leq 3000

1 \leq X \leq 2N

N and X are integers.

Input

Input is given from Standard Input in the following format:

N X

Output

Print the number, modulo 998244353, of sequences that satisfy the condition.

Sample Input 1

3 3

Sample Output 1

14

14 sequences satisfy the condition: (0,0,0),(0,0,1),(0,0,2),(0,1,0),(0,1,1),(0,2,0),(0,2,2),(1,0,0),(1,0,1),(1,1,0),(2,0,0),(2,0,2),(2,2,0) and (2,2,2).

Sample Input 2

8 6

Sample Output 2

1179

Sample Input 3

10 1

Sample Output 3

1024

Sample Input 4

9 13

Sample Output 4

18402

Sample Input 5

314 159

Sample Output 5

459765451

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 3555;
const int K = 700 ;
int c[N][N], dp[N][N], a[N];
int n, x, b[N], res;
void gen(int m){
    if (m == n + 1){
        int q = 1;
        for (int i = 1; q &&  i <= n; i++){
            int s = 0;
            for (int j = i;q &&  j <= n; j++){
                s += b[j];
                if (s == x) q = 0;
            }
        }
        if (q == 1){
            for (int i = 1; i <= n; i++) if (b[i] != 0) cout << b[i] << " ";
            cout << endl;
        }
        res += q;
        return;
    }
    b[m] = 0;
    gen(m + 1);
    b[m] = 1;
    gen(m + 1);
    b[m] = 2;
    gen(m + 1);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> x;
   // gen(1);
    c[0][0] = 1;
    for (int i = 1; i <= n; i++){
        c[i][0] = 1;
        for (int j = 1; j <= i; j++){
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n + n; j++){
            dp[i][j] = dp[i - 1][j - 1];
            if (j > 1) dp[i][j] = (dp[i][j] + dp[i - 1][j - 2]) % mod;
        }
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j < x; j++) a[i] = (a[i] + dp[i][j]) % mod;
        for (int j = 1; j <= i; j++){
            int l = j + 1;
            int r = i - j;
            if (r < l) continue;
            if (x - 1 - 2 * j >= 0 && (r - l + 1) * 2 != (x - 1 - 2 * j)) a[i] = (a[i] + dp[r - l + 1][x - 1 - 2 * j]) % mod;
        }
        if (i != 0 && 2 * i > x && x % 2 == 1) a[i] = (a[i] + 1) % mod;
    }
    int ans = 0;
    for (int i = 0; i <= n; i++){;
        ans = (ans + c[n][i] * a[i]) % mod;
    }
    cout << ans;
}