# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
251867 | dantoh000 | Naan (JOI19_naan) | C++14 | 2 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[i][j].second > (__int128)best.second*p[i][j].first){
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |