# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170731 | 2019-12-26T08:36:20 Z | arnold518 | Naan (JOI19_naan) | C++14 | 1955 ms | 116868 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2000; const ll INF = numeric_limits<ll>::max(); struct Frac { ll x, y; Frac() {} Frac(ll x, ll y) : x(x), y(y) {} void norm() { ll g=__gcd(x, y); x/=g; y/=g; } }; bool operator < (const Frac &p, const Frac &q) { return (__int128)p.y*q.x<(__int128)q.y*p.x; } int N, L; ll A[MAXN+10][MAXN+10]; Frac B[MAXN+10][MAXN+10]; bool vis[MAXN+10]; int ans[MAXN+10]; int main() { int i, j; scanf("%d%d", &N, &L); for(i=1; i<=N; i++) { ll S=0; for(j=1; j<=L; j++) scanf("%lld", &A[i][j]), S+=A[i][j]; for(j=1; j<=L; j++) A[i][j]*=N; for(j=1; j<=L; j++) A[i][j]+=A[i][j-1]; for(j=1; j<N; j++) { ll now=j*S; int pos=upper_bound(A[i], A[i]+L+1, now)-A[i]; now-=A[i][pos-1]; Frac t; t.x=(A[i][pos]-A[i][pos-1]); t.y=now+(A[i][pos]-A[i][pos-1])*(pos-1); t.norm(); B[i][j]=t; } } for(i=1; i<N; i++) { pair<Frac, int> val; val.first={1, INF}; val.second=-1; for(j=1; j<=N; j++) { if(vis[j]) continue; pair<Frac, int> now; now.first=B[j][i]; now.second=j; val=min(val, now); } ans[i]=val.second; vis[val.second]=true; printf("%lld %lld\n", val.first.y, val.first.x); } for(i=1; i<=N; i++) if(!vis[i]) ans[N]=i; for(i=1; i<=N; i++) printf("%d ", ans[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 248 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 380 KB | Output is correct |
10 | Correct | 2 ms | 380 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 3 ms | 376 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 380 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 3 ms | 504 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 380 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 504 KB | Output is correct |
10 | Correct | 4 ms | 504 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 504 KB | Output is correct |
15 | Correct | 3 ms | 508 KB | Output is correct |
16 | Correct | 3 ms | 504 KB | Output is correct |
17 | Correct | 3 ms | 504 KB | Output is correct |
18 | Correct | 3 ms | 504 KB | Output is correct |
19 | Correct | 4 ms | 504 KB | Output is correct |
20 | Correct | 3 ms | 504 KB | Output is correct |
21 | Correct | 7 ms | 504 KB | Output is correct |
22 | Correct | 3 ms | 504 KB | Output is correct |
23 | Correct | 2 ms | 376 KB | Output is correct |
24 | Correct | 3 ms | 376 KB | Output is correct |
25 | Correct | 3 ms | 504 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 3 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 248 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 380 KB | Output is correct |
10 | Correct | 2 ms | 380 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 3 ms | 376 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 3 ms | 504 KB | Output is correct |
18 | Correct | 3 ms | 380 KB | Output is correct |
19 | Correct | 3 ms | 512 KB | Output is correct |
20 | Correct | 3 ms | 504 KB | Output is correct |
21 | Correct | 3 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 380 KB | Output is correct |
23 | Correct | 3 ms | 376 KB | Output is correct |
24 | Correct | 3 ms | 504 KB | Output is correct |
25 | Correct | 4 ms | 504 KB | Output is correct |
26 | Correct | 3 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 3 ms | 376 KB | Output is correct |
29 | Correct | 3 ms | 504 KB | Output is correct |
30 | Correct | 3 ms | 508 KB | Output is correct |
31 | Correct | 3 ms | 504 KB | Output is correct |
32 | Correct | 3 ms | 504 KB | Output is correct |
33 | Correct | 3 ms | 504 KB | Output is correct |
34 | Correct | 4 ms | 504 KB | Output is correct |
35 | Correct | 3 ms | 504 KB | Output is correct |
36 | Correct | 7 ms | 504 KB | Output is correct |
37 | Correct | 3 ms | 504 KB | Output is correct |
38 | Correct | 2 ms | 376 KB | Output is correct |
39 | Correct | 3 ms | 376 KB | Output is correct |
40 | Correct | 3 ms | 504 KB | Output is correct |
41 | Correct | 2 ms | 376 KB | Output is correct |
42 | Correct | 3 ms | 504 KB | Output is correct |
43 | Correct | 167 ms | 13384 KB | Output is correct |
44 | Correct | 1020 ms | 63928 KB | Output is correct |
45 | Correct | 371 ms | 28960 KB | Output is correct |
46 | Correct | 37 ms | 4088 KB | Output is correct |
47 | Correct | 606 ms | 42588 KB | Output is correct |
48 | Correct | 1406 ms | 75592 KB | Output is correct |
49 | Correct | 315 ms | 24144 KB | Output is correct |
50 | Correct | 1714 ms | 95868 KB | Output is correct |
51 | Correct | 590 ms | 41848 KB | Output is correct |
52 | Correct | 1426 ms | 87220 KB | Output is correct |
53 | Correct | 1302 ms | 80952 KB | Output is correct |
54 | Correct | 3 ms | 416 KB | Output is correct |
55 | Correct | 690 ms | 44280 KB | Output is correct |
56 | Correct | 800 ms | 56440 KB | Output is correct |
57 | Correct | 670 ms | 49528 KB | Output is correct |
58 | Correct | 1207 ms | 78840 KB | Output is correct |
59 | Correct | 656 ms | 46200 KB | Output is correct |
60 | Correct | 1708 ms | 116744 KB | Output is correct |
61 | Correct | 1750 ms | 116712 KB | Output is correct |
62 | Correct | 1955 ms | 116484 KB | Output is correct |
63 | Correct | 1813 ms | 116868 KB | Output is correct |
64 | Correct | 1773 ms | 116864 KB | Output is correct |
65 | Correct | 1856 ms | 103600 KB | Output is correct |
66 | Correct | 1845 ms | 103532 KB | Output is correct |
67 | Correct | 1672 ms | 103640 KB | Output is correct |
68 | Correct | 733 ms | 60280 KB | Output is correct |
69 | Correct | 686 ms | 56792 KB | Output is correct |
70 | Correct | 906 ms | 72156 KB | Output is correct |
71 | Correct | 1092 ms | 82308 KB | Output is correct |