# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
370451 |
2021-02-24T03:26:03 Z |
CodePlatina |
Naan (JOI19_naan) |
C++17 |
|
1030 ms |
119736 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define tlll tuple<long long, long long, long long>
#define tllll tuple<long long, long long, long long, long long>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k; cin >> n >> k;
int A[n][k];
for(int i = 0; i < n; ++i)
for(int j = 0; j < k; ++j)
cin >> A[i][j];
vector<plll> ls[n - 1];
for(int i = 0; i < n; ++i)
{
long long s = 0;
for(int j = 0; j < k; ++j) s += A[i][j];
int pt = 0;
long long pf = 0;
for(int j = 0; j < n - 1; ++j)
{
while(pt < k && (pf + A[i][pt]) * n <= s * (j + 1)) pf += A[i][pt++];
ls[j].push_back({i, { s * (j + 1) - pf * n + 1ll * pt * A[i][pt] * n, A[i][pt] * n }});
}
}
for(int i = 0; i < n - 1; ++i) sort(ls[i].begin(), ls[i].end(), [](plll x, plll y)
{
if(x.ee / x.rr != y.ee / y.rr) return x.ee / x.rr < y.ee / y.rr;
return (x.ee % x.rr) * y.rr < x.rr * (y.ee % y.rr);
});
// for(auto i : ls)
// {
// for(auto [j, k] : i) cout << j << ' ' << k.ff << ' ' << k.ss << endl;
// cout << endl;
// }
bool chc[n]{};
int P[n];
pll ans[n];
for(int i = 0; i < n - 1; ++i)
{
for(int j = 0; j < n; ++j) if(!chc[ls[i][j].ff])
{
chc[ls[i][j].ff] = true;
P[i] = (int)ls[i][j].ff;
ans[i] = ls[i][j].ss;
break;
}
}
for(int i = 0; i < n; ++i) if(!chc[i]) P[n - 1] = i;
for(int i = 0; i < n - 1; ++i) cout << ans[i].ff << ' ' << ans[i].ss << '\n';
for(int i = 0; i < n; ++i) cout << P[i] + 1 << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
87 ms |
13096 KB |
Output is correct |
44 |
Correct |
562 ms |
65132 KB |
Output is correct |
45 |
Correct |
215 ms |
28268 KB |
Output is correct |
46 |
Correct |
22 ms |
2668 KB |
Output is correct |
47 |
Correct |
328 ms |
37740 KB |
Output is correct |
48 |
Correct |
822 ms |
96060 KB |
Output is correct |
49 |
Correct |
185 ms |
24556 KB |
Output is correct |
50 |
Correct |
1030 ms |
111084 KB |
Output is correct |
51 |
Correct |
342 ms |
51052 KB |
Output is correct |
52 |
Correct |
872 ms |
98412 KB |
Output is correct |
53 |
Correct |
772 ms |
91776 KB |
Output is correct |
54 |
Correct |
1 ms |
364 KB |
Output is correct |
55 |
Correct |
404 ms |
61420 KB |
Output is correct |
56 |
Correct |
470 ms |
66772 KB |
Output is correct |
57 |
Correct |
408 ms |
59116 KB |
Output is correct |
58 |
Correct |
725 ms |
90612 KB |
Output is correct |
59 |
Correct |
369 ms |
57068 KB |
Output is correct |
60 |
Correct |
860 ms |
112892 KB |
Output is correct |
61 |
Correct |
862 ms |
112696 KB |
Output is correct |
62 |
Correct |
994 ms |
113516 KB |
Output is correct |
63 |
Correct |
958 ms |
113532 KB |
Output is correct |
64 |
Correct |
914 ms |
113696 KB |
Output is correct |
65 |
Correct |
771 ms |
119564 KB |
Output is correct |
66 |
Correct |
771 ms |
119736 KB |
Output is correct |
67 |
Correct |
806 ms |
119652 KB |
Output is correct |
68 |
Correct |
375 ms |
71532 KB |
Output is correct |
69 |
Correct |
379 ms |
66412 KB |
Output is correct |
70 |
Correct |
461 ms |
84204 KB |
Output is correct |
71 |
Correct |
562 ms |
89708 KB |
Output is correct |