Submission #164748

#TimeUsernameProblemLanguageResultExecution timeMemory
164748ho94949Naan (JOI19_naan)C++17
29 / 100
273 ms5244 KiB
#include<bits/stdc++.h> using namespace std; using frac = pair<long long, long long>; int N, L; int V[2020][2020]; frac happy[2020]; frac cut[2020]; frac cut2[2020]; int P[2020]; frac X[2020]; bool used[2020]; void deb(frac a) { cout <<a.first << " " <<a.second<<endl; } frac nor(frac t) { long long a, b; tie(a, b) = t; long long g = __gcd(a, b); return frac(a/g, b/g); } frac operator +(frac a, frac b) { long long x, y, z, w; tie(x, y) = a; tie(z, w) = b; return nor(frac(x*w+y*z, y*w)); } frac operator -(frac a, frac b) { long long x, y, z, w; tie(x, y) = a; tie(z, w) = b; return nor(frac(x*w-y*z, y*w)); } bool operator < (frac a, frac b) { long long x, y, z, w; tie(x, y) = a; tie(z, w) = b; return x*w < y*z; } int main() { scanf("%d%d", &N, &L); for(int i=0; i<N; ++i) { happy[i].second = N; for(int j=0; j<L; ++j) { scanf("%d", &V[i][j]); happy[i].first += V[i][j]; } happy[i] = nor(happy[i]); cut[i] = cut2[i] = frac(0, 1); } //cut: happyness now //cut2: happyness future int phase = 0; frac now = frac(0, 1); while(phase < N-1) { int nextint = now.first / now.second + 1; frac diff = frac(nextint, 1) - now; frac minv = frac(0, 1); int mini = -1; for(int i=0; i<N; ++i) { if(used[i]) continue; frac h = diff; h.first *= V[i][nextint-1]; h = nor(h); cut2[i] = cut[i] + h; if(!(cut2[i] < happy[i])) { frac np = (happy[i]-cut[i]); np.second *= V[i][nextint-1]; np = np + now; if(mini == -1 || np < minv) { mini = i; minv = np; } } } if(mini != -1) { X[phase] = minv; P[phase] = mini; used[mini] = true; for(int i=0; i<N; ++i) cut[i] = frac(0, 1); now = minv; ++phase; } else { for(int i=0; i<N; ++i) cut[i] = cut2[i]; now = frac(nextint, 1); } } for(int i=0; i<N-1; ++i) printf("%lld %lld\n", X[i].first, X[i].second); 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); return 0; }

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:49: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:55: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...