Hi there. So I was (and still am) trying to code a solution for [problem:1954D]. One of the main implementation here is the knapsack DP, but somehow there was an issue on the variables. So I went to retype **just** the knapsack code and debug it like the following:↵
↵
↵
~~~~~↵
#include <bits/stdc++.h>↵
↵
using namespace std;↵
↵
long long dp[5000];↵
int a[5000];↵
↵
int main() {↵
int n;↵
cin >> n;↵
for (int i=0;i<n;i++) {↵
cin >> a[i];↵
for (int j=5000-a[i];j>=0;j--) dp[j+a[i]]=(dp[j+a[i]]+dp[j])%998244353;↵
}↵
for (int i=0;i<n;i++) cout << a[i] << ' ';↵
cout << endl;↵
}↵
~~~~~↵
↵
So, I was testing this input for this code:↵
↵
↵
~~~~~↵
3↵
1 1 2↵
~~~~~↵
↵
and in my local VS Code g++17 compiler it results in this:↵
↵
~~~~~↵
301989885 0 2↵
~~~~~↵
↵
while in Codeforces g++17, it results in this:↵
↵
↵
~~~~~↵
1 1 2↵
~~~~~↵
↵
Does anyone know why this happened? If so, please let me know :>↵
↵
Edit: So apparently, the local compiler produce the correct output if I change 5000 to 5001 or 4999. Now I'm more tempted to know on why 5000 specifically fails.
↵
↵
~~~~~↵
#include <bits/stdc++.h>↵
↵
using namespace std;↵
↵
long long dp[5000];↵
int a[5000];↵
↵
int main() {↵
int n;↵
cin >> n;↵
for (int i=0;i<n;i++) {↵
cin >> a[i];↵
for (int j=5000-a[i];j>=0;j--) dp[j+a[i]]=(dp[j+a[i]]+dp[j])%998244353;↵
}↵
for (int i=0;i<n;i++) cout << a[i] << ' ';↵
cout << endl;↵
}↵
~~~~~↵
↵
So, I was testing this input for this code:↵
↵
↵
~~~~~↵
3↵
1 1 2↵
~~~~~↵
↵
and in my local VS Code g++17 compiler it results in this:↵
↵
~~~~~↵
301989885 0 2↵
~~~~~↵
↵
while in Codeforces g++17, it results in this:↵
↵
↵
~~~~~↵
1 1 2↵
~~~~~↵
↵
Does anyone know why this happened? If so, please let me know :>↵
↵
Edit: So apparently, the local compiler produce the correct output if I change 5000 to 5001 or 4999. Now I'm more tempted to know on why 5000 specifically fails.