# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
278765 |
2020-08-21T20:43:54 Z |
caoash |
Naan (JOI19_naan) |
C++14 |
|
1701 ms |
148872 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
struct fr{
__int128 x, y;
fr(__int128 X = 0, __int128 Y = 1){
x = X, y = Y;
ll g = __gcd(x, y);
x /= g, y /= g;
}
friend fr operator+(fr a, fr b){
return fr(a.x * b.y + b.x * a.y, a.y * b.y);
}
friend fr operator-(fr a, fr b){
return fr(a.x * b.y - b.x * a.y, a.y * b.y);
}
friend fr operator*(fr a, fr b){
return fr(a.x * b.x, a.y * b.y);
}
friend fr operator/(fr a, fr b){
return fr(a.x * b.y, a.y * b.x);
}
friend bool operator<(fr a, fr b){
return a.x * b.y < b.x * a.y;
}
};
const int MX = 2005;
bool used[MX]; fr V[MX][MX]; fr need[MX], dist[MX], ans[MX]; int ind[MX];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N, L; cin >> N >> L;
for (int i = 0; i < N; i++) {
for (int j = 0; j < L; j++) {
ll x; cin >> x;
V[i][j] = fr(x);
if (j != 0) V[i][j] = V[i][j] + V[i][j - 1];
}
}
for (int i = 0; i < N; i++) {
ans[i] = fr(L + 1);
for (int j = 0; j < N; j++) {
if (used[j]) {
continue;
}
fr need = V[j][L - 1] * fr(i + 1, N);
// cout << "i, need: " << i << " " << (ll) need.x << " " << (ll) need.y << '\n';
int it = lower_bound(V[j], V[j] + L - 1, need) - V[j] - 1;
// cout << i << " " << it << endl;
fr to_add = fr(it + 1) + (need - V[j][it]) / (V[j][it + 1] - V[j][it]);
if (to_add < ans[i]) {
ans[i] = to_add;
ind[i] = j;
}
}
if(i < N - 1) cout << (ll) ans[i].x << " " << (ll) ans[i].y << '\n';
used[ind[i]] = true;
}
for (int i = 0; i < N; i++) {
cout << ind[i] + 1 << " ";
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
126328 KB |
Output is correct |
2 |
Correct |
67 ms |
126456 KB |
Output is correct |
3 |
Correct |
66 ms |
126456 KB |
Output is correct |
4 |
Correct |
67 ms |
126456 KB |
Output is correct |
5 |
Correct |
67 ms |
126456 KB |
Output is correct |
6 |
Correct |
66 ms |
126328 KB |
Output is correct |
7 |
Correct |
66 ms |
126456 KB |
Output is correct |
8 |
Correct |
66 ms |
126456 KB |
Output is correct |
9 |
Correct |
65 ms |
126456 KB |
Output is correct |
10 |
Correct |
72 ms |
126428 KB |
Output is correct |
11 |
Correct |
67 ms |
126456 KB |
Output is correct |
12 |
Correct |
74 ms |
126364 KB |
Output is correct |
13 |
Correct |
65 ms |
126456 KB |
Output is correct |
14 |
Correct |
66 ms |
126460 KB |
Output is correct |
15 |
Correct |
66 ms |
126456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
126328 KB |
Output is correct |
2 |
Correct |
75 ms |
126456 KB |
Output is correct |
3 |
Correct |
67 ms |
126456 KB |
Output is correct |
4 |
Correct |
67 ms |
126456 KB |
Output is correct |
5 |
Correct |
68 ms |
126456 KB |
Output is correct |
6 |
Correct |
66 ms |
126456 KB |
Output is correct |
7 |
Correct |
67 ms |
126456 KB |
Output is correct |
8 |
Correct |
66 ms |
126456 KB |
Output is correct |
9 |
Correct |
70 ms |
126456 KB |
Output is correct |
10 |
Correct |
71 ms |
126456 KB |
Output is correct |
11 |
Correct |
66 ms |
126456 KB |
Output is correct |
12 |
Correct |
67 ms |
126460 KB |
Output is correct |
13 |
Correct |
66 ms |
126456 KB |
Output is correct |
14 |
Correct |
70 ms |
126456 KB |
Output is correct |
15 |
Correct |
66 ms |
126604 KB |
Output is correct |
16 |
Correct |
67 ms |
126456 KB |
Output is correct |
17 |
Correct |
66 ms |
126456 KB |
Output is correct |
18 |
Correct |
68 ms |
126456 KB |
Output is correct |
19 |
Correct |
66 ms |
126460 KB |
Output is correct |
20 |
Correct |
67 ms |
126456 KB |
Output is correct |
21 |
Correct |
67 ms |
126456 KB |
Output is correct |
22 |
Correct |
68 ms |
126332 KB |
Output is correct |
23 |
Correct |
67 ms |
126460 KB |
Output is correct |
24 |
Correct |
67 ms |
126456 KB |
Output is correct |
25 |
Correct |
66 ms |
126456 KB |
Output is correct |
26 |
Correct |
66 ms |
126456 KB |
Output is correct |
27 |
Correct |
69 ms |
126712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
126328 KB |
Output is correct |
2 |
Correct |
67 ms |
126456 KB |
Output is correct |
3 |
Correct |
66 ms |
126456 KB |
Output is correct |
4 |
Correct |
67 ms |
126456 KB |
Output is correct |
5 |
Correct |
67 ms |
126456 KB |
Output is correct |
6 |
Correct |
66 ms |
126328 KB |
Output is correct |
7 |
Correct |
66 ms |
126456 KB |
Output is correct |
8 |
Correct |
66 ms |
126456 KB |
Output is correct |
9 |
Correct |
65 ms |
126456 KB |
Output is correct |
10 |
Correct |
72 ms |
126428 KB |
Output is correct |
11 |
Correct |
67 ms |
126456 KB |
Output is correct |
12 |
Correct |
74 ms |
126364 KB |
Output is correct |
13 |
Correct |
65 ms |
126456 KB |
Output is correct |
14 |
Correct |
66 ms |
126460 KB |
Output is correct |
15 |
Correct |
66 ms |
126456 KB |
Output is correct |
16 |
Correct |
67 ms |
126328 KB |
Output is correct |
17 |
Correct |
75 ms |
126456 KB |
Output is correct |
18 |
Correct |
67 ms |
126456 KB |
Output is correct |
19 |
Correct |
67 ms |
126456 KB |
Output is correct |
20 |
Correct |
68 ms |
126456 KB |
Output is correct |
21 |
Correct |
66 ms |
126456 KB |
Output is correct |
22 |
Correct |
67 ms |
126456 KB |
Output is correct |
23 |
Correct |
66 ms |
126456 KB |
Output is correct |
24 |
Correct |
70 ms |
126456 KB |
Output is correct |
25 |
Correct |
71 ms |
126456 KB |
Output is correct |
26 |
Correct |
66 ms |
126456 KB |
Output is correct |
27 |
Correct |
67 ms |
126460 KB |
Output is correct |
28 |
Correct |
66 ms |
126456 KB |
Output is correct |
29 |
Correct |
70 ms |
126456 KB |
Output is correct |
30 |
Correct |
66 ms |
126604 KB |
Output is correct |
31 |
Correct |
67 ms |
126456 KB |
Output is correct |
32 |
Correct |
66 ms |
126456 KB |
Output is correct |
33 |
Correct |
68 ms |
126456 KB |
Output is correct |
34 |
Correct |
66 ms |
126460 KB |
Output is correct |
35 |
Correct |
67 ms |
126456 KB |
Output is correct |
36 |
Correct |
67 ms |
126456 KB |
Output is correct |
37 |
Correct |
68 ms |
126332 KB |
Output is correct |
38 |
Correct |
67 ms |
126460 KB |
Output is correct |
39 |
Correct |
67 ms |
126456 KB |
Output is correct |
40 |
Correct |
66 ms |
126456 KB |
Output is correct |
41 |
Correct |
66 ms |
126456 KB |
Output is correct |
42 |
Correct |
69 ms |
126712 KB |
Output is correct |
43 |
Correct |
183 ms |
127992 KB |
Output is correct |
44 |
Correct |
841 ms |
136568 KB |
Output is correct |
45 |
Correct |
348 ms |
134008 KB |
Output is correct |
46 |
Correct |
90 ms |
127608 KB |
Output is correct |
47 |
Correct |
537 ms |
134696 KB |
Output is correct |
48 |
Correct |
1317 ms |
128440 KB |
Output is correct |
49 |
Correct |
327 ms |
127480 KB |
Output is correct |
50 |
Correct |
1589 ms |
132104 KB |
Output is correct |
51 |
Correct |
591 ms |
130296 KB |
Output is correct |
52 |
Correct |
1329 ms |
133620 KB |
Output is correct |
53 |
Correct |
1206 ms |
131576 KB |
Output is correct |
54 |
Correct |
68 ms |
126456 KB |
Output is correct |
55 |
Correct |
574 ms |
126972 KB |
Output is correct |
56 |
Correct |
761 ms |
130936 KB |
Output is correct |
57 |
Correct |
682 ms |
129912 KB |
Output is correct |
58 |
Correct |
1096 ms |
130424 KB |
Output is correct |
59 |
Correct |
632 ms |
130552 KB |
Output is correct |
60 |
Correct |
1503 ms |
148600 KB |
Output is correct |
61 |
Correct |
1523 ms |
148728 KB |
Output is correct |
62 |
Correct |
1701 ms |
148428 KB |
Output is correct |
63 |
Correct |
1641 ms |
148728 KB |
Output is correct |
64 |
Correct |
1543 ms |
148872 KB |
Output is correct |
65 |
Correct |
1619 ms |
135288 KB |
Output is correct |
66 |
Correct |
1593 ms |
135196 KB |
Output is correct |
67 |
Correct |
1460 ms |
135236 KB |
Output is correct |
68 |
Correct |
699 ms |
132472 KB |
Output is correct |
69 |
Correct |
667 ms |
134136 KB |
Output is correct |
70 |
Correct |
861 ms |
132984 KB |
Output is correct |
71 |
Correct |
1012 ms |
137592 KB |
Output is correct |