Submission #251869

#TimeUsernameProblemLanguageResultExecution timeMemory
251869dantoh000Naan (JOI19_naan)C++14
100 / 100
1057 ms85496 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> ii; int n,l; ii p[2005][2005]; int vis[2005]; ll a[2005]; int ord[2005]; int main(){ scanf("%d%d",&n,&l); for (int i = 1; i <= n; i++){ ll s = 0; for (int j = 1; j <= l; j++){ scanf("%lld",&a[j]); s += a[j]; } ll o = 0, k = 0; for (int j = 1; j <= n; j++){ while (k < l && (o+a[k])*n < s*j) o += a[k++]; ll A = 1ll*(k-1)*a[k]*n + s*j - o*n; ll B = 1ll*a[k]*n; ll D = __gcd(A,B); p[i][j] = ii(A/D, B/D); } } for (int i = 1; i <= n; i++){ ii best = {1,0}; int cur; for (int j = 1; j <= n; j++){ if (vis[j] == 0){ if ((__int128)best.first*p[j][i].second > (__int128)best.second*p[j][i].first){ best = p[j][i]; cur = j; } } } ord[i] = cur; vis[cur] = 1; if (i != n) printf("%lld %lld\n",best.first,best.second); } for (int i = 1; i <= n; i++){ printf("%d ",ord[i]); } }

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:11: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:15:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&a[j]);
             ~~~~~^~~~~~~~~~~~~~
naan.cpp:39:16: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
         ord[i] = cur;
         ~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...