# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
123993 | 2019-07-02T10:32:41 Z | onjo0127 | Naan (JOI19_naan) | C++11 | 2 ms | 376 KB |
#include <bits/stdc++.h> using namespace std; using ll = __int128; using pll = pair<ll, ll>; #define X first #define Y second const pll INF = {1LL*1e18, 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, sa = 0, sb = 1; tie(sa, sb) = f(sa, sb); for(int j=0, k=1; j<L; j++) { // sa / sb + V[i][j] >= A[i] / N * k if((__int128)sa * N + (__int128)V[i][j] * sb * N >= (__int128)A[i] * sb * k) { // (a / b) * V[i][j] + (sa / sb) == A[i] / N * k // a/b * V[i][j] * sb * N + sa * N == A[i] * sb * k // a/b * V[i][j] * sb * N == A[i] * sb * k - sa * N; b = (__int128)V[i][j] * sb * N; a = (__int128)b * j + (__int128)A[i] * sb * k - (__int128)sa * N; D[i][k] = f(a, b); ++k; } sa += (__int128)sb * V[i][j]; tie(sa, sb) = f(sa, sb); } } 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", pos[i].X, pos[i].Y); for(auto& it: P) printf("%d ", it); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Integer parameter [name=B_i] equals to 0, violates the range [1, 1000000000] |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Integer parameter [name=B_i] equals to 0, violates the range [1, 1000000000] |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Integer parameter [name=B_i] equals to 0, violates the range [1, 1000000000] |
2 | Halted | 0 ms | 0 KB | - |