Submission #251866

#TimeUsernameProblemLanguageResultExecution timeMemory
251866dantoh000Naan (JOI19_naan)C++14
0 / 100
2 ms384 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;
        int cur;
        int first = 1;
        for (int j = 1; j <= n; j++){
            if (vis[j] == 0){
                if (first || (__int128)best.first*p[i][j].second > (__int128)best.second*p[i][j].first){
                    first = 0;
                    best = p[i][j];
                    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:41: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...