# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124451 | 2019-07-03T11:03:03 Z | songc | Naan (JOI19_naan) | C++14 | 199 ms | 255876 KB |
#include <bits/stdc++.h> using namespace std; typedef __int128 LL; typedef pair<int, int> pii; int N, K=1, L; bool chk[2020]; struct Rat{ LL p=1, q=0; Rat(){} Rat(LL x, LL y){p = y, q = x;} Rat operator+(const Rat &r)const{ LL g = __gcd(q*r.p + r.q*p, p*r.p); return Rat((q*r.p + r.q*p)/g, p*r.p / g); } Rat operator-(const Rat &r)const{ LL g = __gcd(q*r.p - r.q*p, p*r.p); return Rat((q*r.p - r.q*p)/g, (p*r.p)/g); } Rat operator*(const Rat &r)const{ LL g = __gcd(q*r.q, p*r.p); return Rat(q*r.q/g, p*r.p/g); } Rat operator/(const Rat &r)const{ LL g = __gcd(q*r.p, p*r.q); return Rat(q*r.p/g, p*r.q/g); } bool operator<(const Rat &r)const{ return q*r.p < r.q*p; } } A[2020][2020], C[2020][2020]; int main(){ scanf("%d %d", &N, &L); for (int i=1; i<=N; i++) { for (int j=1; j<=L; j++) { scanf("%lld", &A[i][j].q); A[i][0] = A[i][0] + A[i][j]; } A[i][0].p = N; } for (int i=1; i<=N; i++){ Rat R = Rat(0, 1); for (int j=1; j<=N; j++){ Rat S = A[i][0]; while (1){ Rat x = A[i][R.q/R.p+1] * (Rat(R.q/R.p+1, 1) - R); if (x < S){ S = S - x; R = Rat(R.q/R.p+1, 1); } else{ R = R + (S / A[i][R.q/R.p+1]); break; } } C[i][j] = R; } } vector<int> V; for (int i=1; i<=N; i++){ Rat Min=Rat(L+1, 1); int id; for (int j=1; j<=N; j++){ if (chk[j]) continue; if (C[j][i] < Min){ Min = C[j][i]; id = j; } } if (i<N) printf("%lld %lld\n", Min.q, Min.p); V.push_back(id); chk[id] = true; } for (int x : V) printf("%d ", x); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 197 ms | 255876 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 | 199 ms | 255864 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 | 197 ms | 255876 KB | Integer parameter [name=B_i] equals to 0, violates the range [1, 1000000000] |
2 | Halted | 0 ms | 0 KB | - |