# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
164759 | ho94949 | Naan (JOI19_naan) | C++17 | 653 ms | 38556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int V[2020][2020];
int N, L;
int cur = 0;
long long sumv[2020], now[2020], cut[2020];
bool used[2020];
int P[2020];
// previous now: cur + now[i]/(N*V[i][cur])
// cut: N*(earned)
int main()
{
scanf("%d%d", &N, &L);
for(int i=0; i<N; ++i)
for(int j=0; j<L; ++j)
{
scanf("%d", &V[i][j]);
sumv[i] += V[i][j];
}
int phase = 0;
while(phase < N-1)
{
int nextint = cur+1;
// minv = f/s
long long f, s;
int mini = -1;
for(int i=0; i<N; ++i)
{
if(used[i]) continue;
long long earn = N*V[i][cur] - now[i];
if(cut[i] + earn >= sumv[i])
{
//ok, can be used
long long nf = now[i] + sumv[i]-cut[i];
long long ns = N*V[i][cur];
if(mini == -1 || f*ns > s*nf)
{
f = nf;
s = ns;
mini = i;
}
}
else
cut[i] += earn;
}
if(mini != -1)
{
printf("%lld %lld\n", cur*s+f, s);
P[phase] = mini;
used[mini] = true;
for(int i=0; i<N; ++i) cut[i] = 0;
for(int i=0; i<N; ++i)
{
if(used[i]) continue;
long long base = N*V[i][cur];
long long upper = (f*base+s-1)/s;
now[i] = upper;
}
++phase;
}
else
{
++cur;
for(int i=0; i<N; ++i) now[i] = 0;
}
}
for(int i=0; i<N-1; ++i)
printf("%d ", P[i]+1);
for(int i=0; i<N; ++i) if(!used[i]) printf("%d\n", i+1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |