Submission #124003

#TimeUsernameProblemLanguageResultExecution timeMemory
124003onjo0127Naan (JOI19_naan)C++11
100 / 100
1756 ms150756 KiB
#include <bits/stdc++.h> using namespace std; using ll = __int128; using pll = pair<ll, ll>; #define X first #define Y second const pll INF = {1e9, 1}; int N, L, V[2009][2009], A[2009]; pll D[2009][2009]; bool operator <(pll P, pll Q) { return (__int128)P.X * Q.Y < (__int128)Q.X * P.Y; } pll f(ll a, ll b) { ll gcd = __gcd(a, b); return {a / gcd, b / gcd}; } void R(int i) { ll a, b, s = 0; int k = 1; for(int j=0; j<L; j++) { // s + V[i][j] >= A[i] / N * k if((__int128)(s + V[i][j]) * N >= (__int128)A[i] * k) { // (a / b) * V[i][j] + s == A[i] / N * k // a/b * V[i][j] * N == A[i] * k - s * N b = (__int128)V[i][j] * N; a = (__int128)j * b + (__int128)A[i] * k - s * N; D[i][k] = f(a, b); ++k; --j; continue; } s += V[i][j]; } while(k <= N) D[i][k++] = {L, 1}; } bool chk[2009]; int main() { scanf("%d%d",&N,&L); for(int i=1; i<=N; i++) { for(int j=0; j<L; j++) { scanf("%d",&V[i][j]); A[i] += V[i][j]; } R(i); } vector<pll> pos; vector<int> P; for(int i=1; i<=N; i++) { pll mn = INF; int mni = -1; for(int j=1; j<=N; j++) if(!chk[j]) { if(D[j][i] < mn) { mn = D[j][i]; mni = j; } } pos.push_back(mn); P.push_back(mni); chk[mni] = 1; } for(int i=0; i<N-1; i++) printf("%lld %lld\n", (long long)pos[i].X, (long long)pos[i].Y); for(auto& it: P) printf("%d ", it); return 0; }

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&N,&L);
  ~~~~~^~~~~~~~~~~~~~
naan.cpp:46:9: 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...