QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#43612 | #4238. Zero Sum | justcyl | WA | 3ms | 4620kb | C++20 | 1.6kb | 2022-08-09 20:17:13 | 2022-08-09 20:17:15 |
Judging History
answer
#include <bits/stdc++.h>
#define F(i, x, y) for (int i = x; i <= y; i++)
#define D(i, x, y) for (int i = x; i >= y; i--)
#define pr printf
#define mst(a,b) memset(a,b,sizeof a)
#define SZ(x) ((int)x.size())
#define ll long long
#define x first
#define y second
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
#define YN(ok) cout << (ok ? "YES" : "NO") << '\n';
#ifdef LOCAL_DEFINE
#include "bits/debug.h"
#else
#define DEB(...)
#endif
using namespace std;
void read(){}
template<typename T,typename... T2>inline void read(T &x,T2 &... oth) { x=0;int ch=getchar(),f=0;while(ch<'0'||ch>'9') { if (ch=='-') f=1;ch=getchar();}while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}if(f)x=-x;read(oth...);}
const int N = 35001,M=4;
const ll inf=1152921504606846976;
vector<ll> f,g;
vector<ll> a[N];
int n,m,C;
bool cmp(vector<ll> u,vector<ll> v){
return u[m+m+1]<v[m+m+1];
}
signed main()
{
#ifdef LOCAL_DEFINE
freopen("temp.in", "r", stdin);
#endif
srand(time(0));
read(n,m);
F(i,1,n){
a[i].resize(m+m+2);
F(j,0,m+m) read(a[i][j]);
a[i][m+m+1]=rand()%(2*n);
}
C=(m*(int)sqrt(n)*3);
DEB(C);
sort(a+1,a+n+1,cmp);
f.pb(0);
F(i,1,n){
g.clear();
F(i,0,min(C,2*m*i)) g.pb(inf);
// DEB(SZ(g));
F(j,0,m+m){
int w=SZ(f)-1;
F(k,0,w){
if(j+k>C) break;
g[j+k]=min(g[j+k],f[k]+a[i][j]);
}
}
swap(f,g);
}
pr("%lld",f[n*m]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 4516kb
input:
3 1 3 14 15 -3 -5 -35 2 71 82
output:
-19
result:
ok 1 number(s): "-19"
Test #2:
score: 0
Accepted
time: 2ms
memory: 4620kb
input:
5 2 1 2 5 14 42 1 2 3 5 8 1 2 4 8 16 1 2 3 4 5 1 2 6 24 120
output:
16
result:
ok 1 number(s): "16"
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 4576kb
input:
10 2 -904071845 760493887 -478285804 759035367 -680013382 -587322944 665345507 -20509293 103731947 864888628 738633646 936703855 -370523881 301151360 478433861 703775172 -913389861 691762973 -185132991 543994805 -511007159 118916858 891184 349354959 267412081 -663269925 14450557 369277951 237764429 ...
output:
0
result:
wrong answer 1st numbers differ - expected: '-6259997315', found: '0'