Submission #164759

#TimeUsernameProblemLanguageResultExecution timeMemory
164759ho94949Naan (JOI19_naan)C++17
100 / 100
653 ms38556 KiB
#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)

naan.cpp: In function 'int main()':
naan.cpp:24:13: warning: unused variable 'nextint' [-Wunused-variable]
         int nextint = cur+1;
             ^~~~~~~
naan.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &L);
     ~~~~~^~~~~~~~~~~~~~~~
naan.cpp:18:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &V[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...