# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
524467 |
2022-02-09T08:59:39 Z |
ParsaAlizadeh |
Naan (JOI19_naan) |
C++17 |
|
1484 ms |
169212 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) begin(x), end(x)
#define kill(x) return cout << x << '\n', 0
#define fst first
#define snd second
void assume(int expr) {
if (!expr) __builtin_unreachable();
}
constexpr int N = 2010;
struct Ratio {
ll c = 0, x = 0, y = 1;
Ratio(ll c) : c(c), x(0), y(1) {}
Ratio(ll c, ll x, ll y) : c(c), x(x), y(y) {
c += (x / y);
x -= y * (x / y);
norm();
}
void norm() {
ll g = __gcd(x, y);
x /= g;
y /= g;
}
Ratio operator+(Ratio const& r) const {
return Ratio{c + r.c, x * r.y + r.x * y, y * r.y};
}
bool operator<(Ratio const& r) const {
if (c != r.c)
return c < r.c;
return x * r.y < y * r.x;
}
void show() const {
ll p = c * y + x, q = y;
cout << p << ' ' << q << '\n';
}
};
int n, L, P[N];
ll V[N][N];
vector<pair<Ratio, int>> E[N];
vector<Ratio> ans;
bitset<N> mark;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> L;
for (int i = 0; i < n; i++) {
ll S = 0;
vector<ll> vec;
vec.reserve(L+1);
vec.push_back(0);
for (int j = 0; j < L; j++) {
cin >> V[i][j];
S += V[i][j];
vec.push_back(S * n);
}
for (int j = 1; j <= n; j++) {
ll x = S * j;
int k = upper_bound(all(vec), x) - begin(vec);
k--;
Ratio start = k;
x -= vec[k];
if (k < L)
start = start + Ratio{0, x, n * V[i][k]};
E[j].emplace_back(start, i);
}
}
fill(all(P), -1);
for (int i = 1; i <= n; i++) {
sort(all(E[i]));
for (auto const& e : E[i]) {
if (mark[e.snd])
continue;
if (!ans.empty() && e.fst < ans.back())
continue;
P[i] = e.snd;
ans.push_back(e.fst);
mark[e.snd] = true;
break;
}
}
for (int i = 0; i < n-1; i++) {
ans[i].show();
}
for (int i = 1; i <= n; i++) {
cout << P[i]+1 << ' ';
}
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
372 KB |
Output is correct |
8 |
Correct |
1 ms |
396 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
372 KB |
Output is correct |
14 |
Correct |
1 ms |
376 KB |
Output is correct |
15 |
Correct |
1 ms |
380 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
380 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
372 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
372 KB |
Output is correct |
23 |
Correct |
1 ms |
396 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
376 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
372 KB |
Output is correct |
29 |
Correct |
1 ms |
376 KB |
Output is correct |
30 |
Correct |
1 ms |
380 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
380 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
376 KB |
Output is correct |
43 |
Correct |
119 ms |
21576 KB |
Output is correct |
44 |
Correct |
727 ms |
105116 KB |
Output is correct |
45 |
Correct |
251 ms |
38552 KB |
Output is correct |
46 |
Correct |
27 ms |
3788 KB |
Output is correct |
47 |
Correct |
416 ms |
55028 KB |
Output is correct |
48 |
Correct |
1135 ms |
135596 KB |
Output is correct |
49 |
Correct |
246 ms |
36228 KB |
Output is correct |
50 |
Correct |
1334 ms |
160576 KB |
Output is correct |
51 |
Correct |
474 ms |
73244 KB |
Output is correct |
52 |
Correct |
1068 ms |
138992 KB |
Output is correct |
53 |
Correct |
973 ms |
131696 KB |
Output is correct |
54 |
Correct |
1 ms |
372 KB |
Output is correct |
55 |
Correct |
541 ms |
86612 KB |
Output is correct |
56 |
Correct |
561 ms |
95504 KB |
Output is correct |
57 |
Correct |
483 ms |
85700 KB |
Output is correct |
58 |
Correct |
860 ms |
130072 KB |
Output is correct |
59 |
Correct |
465 ms |
80020 KB |
Output is correct |
60 |
Correct |
1096 ms |
163184 KB |
Output is correct |
61 |
Correct |
1183 ms |
163132 KB |
Output is correct |
62 |
Correct |
1484 ms |
162760 KB |
Output is correct |
63 |
Correct |
1351 ms |
163100 KB |
Output is correct |
64 |
Correct |
1223 ms |
163116 KB |
Output is correct |
65 |
Correct |
1241 ms |
169064 KB |
Output is correct |
66 |
Correct |
1233 ms |
169212 KB |
Output is correct |
67 |
Correct |
1121 ms |
169164 KB |
Output is correct |
68 |
Correct |
488 ms |
102000 KB |
Output is correct |
69 |
Correct |
437 ms |
94208 KB |
Output is correct |
70 |
Correct |
584 ms |
119744 KB |
Output is correct |
71 |
Correct |
736 ms |
130552 KB |
Output is correct |