#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
// #define fisier 1
using namespace std;
typedef long long ll;
int n, l;
int mat[2002][2002];
ll num[2002][2002], den[2002][2002];
bool tk[2002];
bool smaller(int a, int b, int pz)
{
double rap = (0.0000 + num[b][pz]) / (0.0000 + den[b][pz]);
double rap2 = (0.0000 + num[a][pz]) / (0.0000 + den[a][pz]);
return (rap < rap2);
}
int main()
{
#ifdef fisier
ifstream f("input.in");
ofstream g("output.out");
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> l;
for(int i = 0; i < n; ++i)
for(int j = 0; j < l; ++j)
cin >> mat[i][j];
for(int i = 0; i < n; ++i)
{
int sum = 0;
for(int j = 0; j < l; ++j)
sum += mat[i][j];
int cursum = 0;
int pp = 0;
for(int j = 0; j < n; ++j)
{
while(1LL * cursum * n < 1LL * sum * (j+1))
cursum += mat[i][pp++];
num[i][j] = 1LL * pp * n * mat[i][pp - 1] - 1LL * cursum * n + 1LL * sum * (j+1);
den[i][j] = 1LL * n * mat[i][pp - 1];
}
}
vector<int> wh;
for(int i = 0; i < n; ++i)
{
int cn = -1;
for(int j = 0; j < n; ++j)
if(!tk[j])
{
if(cn == -1 || smaller(cn, j, i))
cn = j;
}
wh.pb(cn);
tk[cn] = 1;
}
for(int i = 0; i < n - 1; ++i)
cout << num[wh[i]][i] << " " << den[wh[i]][i] << '\n';
for(int i = 0; i < wh.size(); ++i)
cout << wh[i] + 1 << " ";
return 0;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:74:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < wh.size(); ++i)
~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
6 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
5 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
44 ms |
13180 KB |
Output is correct |
44 |
Correct |
252 ms |
61048 KB |
Output is correct |
45 |
Correct |
154 ms |
26104 KB |
Output is correct |
46 |
Correct |
26 ms |
3576 KB |
Output is correct |
47 |
Correct |
189 ms |
39392 KB |
Output is correct |
48 |
Correct |
152 ms |
71928 KB |
Output is correct |
49 |
Correct |
54 ms |
25592 KB |
Output is correct |
50 |
Correct |
248 ms |
83192 KB |
Output is correct |
51 |
Correct |
139 ms |
37624 KB |
Output is correct |
52 |
Correct |
276 ms |
74488 KB |
Output is correct |
53 |
Correct |
215 ms |
71288 KB |
Output is correct |
54 |
Correct |
5 ms |
376 KB |
Output is correct |
55 |
Correct |
67 ms |
49016 KB |
Output is correct |
56 |
Correct |
178 ms |
51324 KB |
Output is correct |
57 |
Correct |
151 ms |
45688 KB |
Output is correct |
58 |
Correct |
191 ms |
70960 KB |
Output is correct |
59 |
Correct |
165 ms |
41848 KB |
Output is correct |
60 |
Correct |
500 ms |
100600 KB |
Output is correct |
61 |
Correct |
521 ms |
100668 KB |
Output is correct |
62 |
Correct |
541 ms |
100488 KB |
Output is correct |
63 |
Correct |
543 ms |
100932 KB |
Output is correct |
64 |
Correct |
503 ms |
100816 KB |
Output is correct |
65 |
Correct |
367 ms |
87480 KB |
Output is correct |
66 |
Correct |
339 ms |
87528 KB |
Output is correct |
67 |
Correct |
343 ms |
87340 KB |
Output is correct |
68 |
Correct |
190 ms |
58104 KB |
Output is correct |
69 |
Correct |
207 ms |
51832 KB |
Output is correct |
70 |
Correct |
206 ms |
68472 KB |
Output is correct |
71 |
Correct |
308 ms |
73716 KB |
Output is correct |