#include <bits/stdc++.h>
using namespace std ;
struct Fraction
{
long long number, numerator, denominator ;
Fraction(long long num = 0): number(num) , numerator(0) , denominator(1) {}
Fraction(long long whole , long long num , long long den): number(whole) , numerator(num) , denominator(den)
{
norm() ;
}
Fraction(long long num , long long den): Fraction(0 , num , den) {}
Fraction& norm()
{
if(numerator > denominator)
{
number += numerator / denominator ;
numerator %= denominator ;
}
long long g = __gcd(numerator , denominator) ;
numerator /= g ;
denominator /= g ;
return *this ;
}
};
bool operator < (const Fraction& a , const Fraction& b)
{
if(a.number != b.number)
return a.number < b.number ;
else
return a.numerator * b.denominator < b.numerator * a.denominator ;
}
ostream& operator << (ostream& cout , const Fraction& a)
{
return cout<<a.number * a.denominator + a.numerator<<" "<<a.denominator ;
}
const int MAX = 2000 + 4 ;
long long arr[MAX][MAX] , sum[MAX] ;
Fraction split[MAX][MAX] ;
int order[MAX] , mark[MAX] ;
int n , l ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>l ;
for(int i = 0 ; i < n ; ++i)
{
for(int j = 0 ; j < l ; ++j)
{
cin>>arr[i][j] ;
sum[i] += arr[i][j] ;
}
}
for(int i = 0 ; i < n ; ++i)
{
long long now = 0 ;
int idx = 0 ;
for(int j = 1 ; j <= n ; ++j)
{
while((now + arr[i][idx]) * n <= sum[i] * j)
{
now += arr[i][idx] ;
++idx ;
}
long long cur = sum[i] * j - now * n ;
split[i][j] = Fraction(idx , cur , n * arr[i][idx]) ;
}
}
for(int i = 1 ; i < n ; ++i)
{
int idx ;
Fraction Min(1e9) ;
for(int j = 0 ; j < n ; ++j)
{
if(mark[j] == 0 && split[j][i] < Min)
{
idx = j ;
Min = split[j][i] ;
}
}
order[i] = idx+1 ;
mark[idx] = 1 ;
cout<<Min<<"\n" ;
}
for(int i = 0 ; i < n ; ++i)
{
if(mark[i] == 0)
order[n] = i+1 ;
}
for(int i = 1 ; i <= n ; ++i)
cout<<order[i]<<" " ;
cout<<"\n" ;
return 0 ;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:92:13: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
mark[idx] = 1 ;
~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94712 KB |
Output is correct |
2 |
Correct |
64 ms |
94712 KB |
Output is correct |
3 |
Correct |
62 ms |
94840 KB |
Output is correct |
4 |
Correct |
58 ms |
94792 KB |
Output is correct |
5 |
Correct |
57 ms |
94840 KB |
Output is correct |
6 |
Correct |
59 ms |
94712 KB |
Output is correct |
7 |
Correct |
64 ms |
94712 KB |
Output is correct |
8 |
Correct |
58 ms |
94712 KB |
Output is correct |
9 |
Correct |
57 ms |
94712 KB |
Output is correct |
10 |
Correct |
62 ms |
94844 KB |
Output is correct |
11 |
Correct |
65 ms |
94840 KB |
Output is correct |
12 |
Correct |
57 ms |
94712 KB |
Output is correct |
13 |
Correct |
58 ms |
94712 KB |
Output is correct |
14 |
Correct |
62 ms |
94712 KB |
Output is correct |
15 |
Correct |
58 ms |
94716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
94840 KB |
Output is correct |
2 |
Correct |
58 ms |
94844 KB |
Output is correct |
3 |
Correct |
60 ms |
94840 KB |
Output is correct |
4 |
Correct |
60 ms |
94840 KB |
Output is correct |
5 |
Correct |
59 ms |
94840 KB |
Output is correct |
6 |
Correct |
57 ms |
94844 KB |
Output is correct |
7 |
Correct |
58 ms |
94712 KB |
Output is correct |
8 |
Correct |
57 ms |
94712 KB |
Output is correct |
9 |
Correct |
66 ms |
94968 KB |
Output is correct |
10 |
Correct |
65 ms |
94840 KB |
Output is correct |
11 |
Correct |
61 ms |
94840 KB |
Output is correct |
12 |
Correct |
60 ms |
94716 KB |
Output is correct |
13 |
Correct |
58 ms |
94840 KB |
Output is correct |
14 |
Correct |
57 ms |
94840 KB |
Output is correct |
15 |
Correct |
59 ms |
94840 KB |
Output is correct |
16 |
Correct |
60 ms |
94840 KB |
Output is correct |
17 |
Correct |
62 ms |
94840 KB |
Output is correct |
18 |
Correct |
58 ms |
94840 KB |
Output is correct |
19 |
Correct |
58 ms |
94840 KB |
Output is correct |
20 |
Correct |
63 ms |
94776 KB |
Output is correct |
21 |
Correct |
60 ms |
94840 KB |
Output is correct |
22 |
Correct |
58 ms |
94840 KB |
Output is correct |
23 |
Correct |
57 ms |
94712 KB |
Output is correct |
24 |
Correct |
57 ms |
94840 KB |
Output is correct |
25 |
Correct |
58 ms |
94844 KB |
Output is correct |
26 |
Correct |
60 ms |
94828 KB |
Output is correct |
27 |
Correct |
57 ms |
94840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
94712 KB |
Output is correct |
2 |
Correct |
64 ms |
94712 KB |
Output is correct |
3 |
Correct |
62 ms |
94840 KB |
Output is correct |
4 |
Correct |
58 ms |
94792 KB |
Output is correct |
5 |
Correct |
57 ms |
94840 KB |
Output is correct |
6 |
Correct |
59 ms |
94712 KB |
Output is correct |
7 |
Correct |
64 ms |
94712 KB |
Output is correct |
8 |
Correct |
58 ms |
94712 KB |
Output is correct |
9 |
Correct |
57 ms |
94712 KB |
Output is correct |
10 |
Correct |
62 ms |
94844 KB |
Output is correct |
11 |
Correct |
65 ms |
94840 KB |
Output is correct |
12 |
Correct |
57 ms |
94712 KB |
Output is correct |
13 |
Correct |
58 ms |
94712 KB |
Output is correct |
14 |
Correct |
62 ms |
94712 KB |
Output is correct |
15 |
Correct |
58 ms |
94716 KB |
Output is correct |
16 |
Correct |
59 ms |
94840 KB |
Output is correct |
17 |
Correct |
58 ms |
94844 KB |
Output is correct |
18 |
Correct |
60 ms |
94840 KB |
Output is correct |
19 |
Correct |
60 ms |
94840 KB |
Output is correct |
20 |
Correct |
59 ms |
94840 KB |
Output is correct |
21 |
Correct |
57 ms |
94844 KB |
Output is correct |
22 |
Correct |
58 ms |
94712 KB |
Output is correct |
23 |
Correct |
57 ms |
94712 KB |
Output is correct |
24 |
Correct |
66 ms |
94968 KB |
Output is correct |
25 |
Correct |
65 ms |
94840 KB |
Output is correct |
26 |
Correct |
61 ms |
94840 KB |
Output is correct |
27 |
Correct |
60 ms |
94716 KB |
Output is correct |
28 |
Correct |
58 ms |
94840 KB |
Output is correct |
29 |
Correct |
57 ms |
94840 KB |
Output is correct |
30 |
Correct |
59 ms |
94840 KB |
Output is correct |
31 |
Correct |
60 ms |
94840 KB |
Output is correct |
32 |
Correct |
62 ms |
94840 KB |
Output is correct |
33 |
Correct |
58 ms |
94840 KB |
Output is correct |
34 |
Correct |
58 ms |
94840 KB |
Output is correct |
35 |
Correct |
63 ms |
94776 KB |
Output is correct |
36 |
Correct |
60 ms |
94840 KB |
Output is correct |
37 |
Correct |
58 ms |
94840 KB |
Output is correct |
38 |
Correct |
57 ms |
94712 KB |
Output is correct |
39 |
Correct |
57 ms |
94840 KB |
Output is correct |
40 |
Correct |
58 ms |
94844 KB |
Output is correct |
41 |
Correct |
60 ms |
94828 KB |
Output is correct |
42 |
Correct |
57 ms |
94840 KB |
Output is correct |
43 |
Correct |
127 ms |
100600 KB |
Output is correct |
44 |
Correct |
457 ms |
123624 KB |
Output is correct |
45 |
Correct |
233 ms |
113016 KB |
Output is correct |
46 |
Correct |
79 ms |
97788 KB |
Output is correct |
47 |
Correct |
315 ms |
117880 KB |
Output is correct |
48 |
Correct |
539 ms |
110840 KB |
Output is correct |
49 |
Correct |
167 ms |
103292 KB |
Output is correct |
50 |
Correct |
700 ms |
128224 KB |
Output is correct |
51 |
Correct |
281 ms |
114860 KB |
Output is correct |
52 |
Correct |
595 ms |
128656 KB |
Output is correct |
53 |
Correct |
526 ms |
124152 KB |
Output is correct |
54 |
Correct |
59 ms |
94840 KB |
Output is correct |
55 |
Correct |
282 ms |
101880 KB |
Output is correct |
56 |
Correct |
354 ms |
119416 KB |
Output is correct |
57 |
Correct |
311 ms |
116088 KB |
Output is correct |
58 |
Correct |
491 ms |
120848 KB |
Output is correct |
59 |
Correct |
326 ms |
116472 KB |
Output is correct |
60 |
Correct |
758 ms |
148116 KB |
Output is correct |
61 |
Correct |
772 ms |
148212 KB |
Output is correct |
62 |
Correct |
823 ms |
147892 KB |
Output is correct |
63 |
Correct |
798 ms |
148256 KB |
Output is correct |
64 |
Correct |
777 ms |
148104 KB |
Output is correct |
65 |
Correct |
761 ms |
134872 KB |
Output is correct |
66 |
Correct |
741 ms |
134824 KB |
Output is correct |
67 |
Correct |
700 ms |
134680 KB |
Output is correct |
68 |
Correct |
315 ms |
119164 KB |
Output is correct |
69 |
Correct |
324 ms |
121848 KB |
Output is correct |
70 |
Correct |
376 ms |
121468 KB |
Output is correct |
71 |
Correct |
464 ms |
130740 KB |
Output is correct |