Submission #210454

#TimeUsernameProblemLanguageResultExecution timeMemory
210454mhy908Naan (JOI19_naan)C++14
100 / 100
635 ms96248 KiB
#include <bits/stdc++.h> #define mp make_pair #define F first #define S second using namespace std; typedef long long LL; typedef pair<LL, LL> pll; const LL llinf=1987654321987654321; int n, m, pr[2010]; pll ans[2010][2010]; LL arr[2010][2010]; bool ch[2010]; bool operator<(pll a, pll b){ return (__int128)a.F*b.S<(__int128)a.S*b.F; } int main(){ scanf("%d %d", &n, &m); for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++)scanf("%lld", &arr[i][j]); } for(int i=1; i<=n; i++){ LL sum=0, temp=arr[i][1]; int pv=1; for(int j=1; j<=m; j++)sum+=arr[i][j]; for(int j=1; j<=n; j++){ while(temp*n<sum*j)temp+=arr[i][++pv]; ans[i][j]=mp(sum*j+arr[i][pv]*n*pv-temp*n, arr[i][pv]*n); } } for(int i=1; i<=n; i++){ pll minn=mp(llinf, 1ll); int temp; for(int j=1; j<=n; j++){ if(!ch[j]&&ans[j][i]<minn){ temp=j; minn=ans[j][i]; } } ch[temp]=true; pr[i]=temp; if(i<n)printf("%lld %lld\n", minn.F, minn.S); } for(int i=1; i<=n; i++)printf("%d ", pr[i]); }

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
naan.cpp:19:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for(int j=1; j<=m; j++)scanf("%lld", &arr[i][j]);
                                ~~~~~^~~~~~~~~~~~~~~~~~~~
naan.cpp:40:17: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
         ch[temp]=true;
         ~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...