QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563368 | #4238. Zero Sum | rotcar07 | ML | 0ms | 0kb | C++20 | 593b | 2024-09-14 10:36:03 | 2024-09-14 10:36:03 |
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=35005,B=805;
typedef long long ll;
int n,id[N],a[N][7],k;
ll dp[N][B*2+1];
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++)
for(int j=0;j<=2*k;j++) cin>>a[i][j];
for(int i=1;i<=n;i++) id[i]=i;
mt19937 rnd(time(0));
shuffle(id+1,id+n+1,rnd);
memset(dp,0x3f,sizeof dp);
int b=B-5;
dp[0][B]=0;
for(int i=1;i<=n;i++)
for(int j=-b;j<=b;j++){
for(int l=-k;l<=k;l++)
dp[i][j+B]=min(dp[i][j+B],dp[i-1][j-l+B]+a[id[i]][l+k]);
}
cout<<dp[n][B]<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
3 1 3 14 15 -3 -5 -35 2 71 82
output:
-19