#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N, K=1, L;
bool chk[2020];
struct Rat{
LL p=1, q=0;
Rat(){}
Rat(LL x, LL y){p = y, q = x;}
Rat operator+(const Rat &r)const{
LL g = __gcd(q*r.p + r.q*p, p*r.p);
return Rat((q*r.p + r.q*p)/g, p*r.p / g);
}
Rat operator-(const Rat &r)const{
LL g = __gcd(q*r.p - r.q*p, p*r.p);
return Rat((q*r.p - r.q*p)/g, (p*r.p)/g);
}
Rat operator*(const Rat &r)const{
LL g = __gcd(q*r.q, p*r.p);
return Rat(q*r.q/g, p*r.p/g);
}
Rat operator/(const Rat &r)const{
LL g = __gcd(q*r.p, p*r.q);
return Rat(q*r.p/g, p*r.q/g);
}
bool operator<(const Rat &r)const{
return (__int128)q*r.p < (__int128)r.q*p;
}
} A[2020][2020], C[2020][2020];
int main(){
scanf("%d %d", &N, &L);
for (int i=1; i<=N; i++) {
for (int j=1; j<=L; j++) {
scanf("%lld", &A[i][j].q);
A[i][0] = A[i][0] + A[i][j];
}
A[i][0].p = N;
}
for (int i=1; i<=N; i++){
Rat R = Rat(0, 1);
for (int j=1; j<=N; j++){
Rat S = A[i][0];
while (1){
Rat x = A[i][R.q/R.p+1] * (Rat(R.q/R.p+1, 1) - R);
if (x < S){
S = S - x;
R = Rat(R.q/R.p+1, 1);
}
else{
R = R + (S / A[i][R.q/R.p+1]);
break;
}
}
C[i][j] = R;
}
}
vector<int> V;
for (int i=1; i<=N; i++){
Rat Min=Rat(L+1, 1);
int id;
for (int j=1; j<=N; j++){
if (chk[j]) continue;
if (C[j][i] < Min){
Min = C[j][i];
id = j;
}
}
if (i<N) printf("%lld %lld\n", Min.q, Min.p);
V.push_back(id);
chk[id] = true;
}
for (int x : V) printf("%d ", x);
return 0;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &L);
~~~~~^~~~~~~~~~~~~~~~~
naan.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &A[i][j].q);
~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
128120 KB |
Output is correct |
2 |
Correct |
101 ms |
128104 KB |
Output is correct |
3 |
Correct |
101 ms |
128120 KB |
Output is correct |
4 |
Correct |
122 ms |
128120 KB |
Output is correct |
5 |
Correct |
100 ms |
128120 KB |
Output is correct |
6 |
Correct |
100 ms |
128120 KB |
Output is correct |
7 |
Correct |
101 ms |
128084 KB |
Output is correct |
8 |
Correct |
102 ms |
128100 KB |
Output is correct |
9 |
Correct |
102 ms |
128120 KB |
Output is correct |
10 |
Correct |
102 ms |
128120 KB |
Output is correct |
11 |
Correct |
101 ms |
128092 KB |
Output is correct |
12 |
Correct |
101 ms |
128092 KB |
Output is correct |
13 |
Correct |
102 ms |
128120 KB |
Output is correct |
14 |
Correct |
101 ms |
128124 KB |
Output is correct |
15 |
Correct |
101 ms |
128032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
128120 KB |
Output is correct |
2 |
Correct |
101 ms |
128100 KB |
Output is correct |
3 |
Correct |
104 ms |
128120 KB |
Output is correct |
4 |
Correct |
102 ms |
128120 KB |
Output is correct |
5 |
Correct |
120 ms |
128160 KB |
Output is correct |
6 |
Correct |
104 ms |
128088 KB |
Output is correct |
7 |
Correct |
100 ms |
128156 KB |
Output is correct |
8 |
Correct |
101 ms |
128120 KB |
Output is correct |
9 |
Correct |
103 ms |
128120 KB |
Output is correct |
10 |
Correct |
102 ms |
128120 KB |
Output is correct |
11 |
Correct |
101 ms |
128120 KB |
Output is correct |
12 |
Correct |
101 ms |
127992 KB |
Output is correct |
13 |
Correct |
101 ms |
128120 KB |
Output is correct |
14 |
Correct |
105 ms |
128120 KB |
Output is correct |
15 |
Correct |
102 ms |
128220 KB |
Output is correct |
16 |
Correct |
103 ms |
128092 KB |
Output is correct |
17 |
Correct |
103 ms |
128120 KB |
Output is correct |
18 |
Correct |
104 ms |
128128 KB |
Output is correct |
19 |
Correct |
122 ms |
128032 KB |
Output is correct |
20 |
Correct |
106 ms |
128120 KB |
Output is correct |
21 |
Correct |
104 ms |
128120 KB |
Output is correct |
22 |
Correct |
104 ms |
128108 KB |
Output is correct |
23 |
Correct |
100 ms |
128120 KB |
Output is correct |
24 |
Correct |
105 ms |
128124 KB |
Output is correct |
25 |
Correct |
102 ms |
128120 KB |
Output is correct |
26 |
Correct |
102 ms |
128124 KB |
Output is correct |
27 |
Correct |
104 ms |
128120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
128120 KB |
Output is correct |
2 |
Correct |
101 ms |
128104 KB |
Output is correct |
3 |
Correct |
101 ms |
128120 KB |
Output is correct |
4 |
Correct |
122 ms |
128120 KB |
Output is correct |
5 |
Correct |
100 ms |
128120 KB |
Output is correct |
6 |
Correct |
100 ms |
128120 KB |
Output is correct |
7 |
Correct |
101 ms |
128084 KB |
Output is correct |
8 |
Correct |
102 ms |
128100 KB |
Output is correct |
9 |
Correct |
102 ms |
128120 KB |
Output is correct |
10 |
Correct |
102 ms |
128120 KB |
Output is correct |
11 |
Correct |
101 ms |
128092 KB |
Output is correct |
12 |
Correct |
101 ms |
128092 KB |
Output is correct |
13 |
Correct |
102 ms |
128120 KB |
Output is correct |
14 |
Correct |
101 ms |
128124 KB |
Output is correct |
15 |
Correct |
101 ms |
128032 KB |
Output is correct |
16 |
Correct |
101 ms |
128120 KB |
Output is correct |
17 |
Correct |
101 ms |
128100 KB |
Output is correct |
18 |
Correct |
104 ms |
128120 KB |
Output is correct |
19 |
Correct |
102 ms |
128120 KB |
Output is correct |
20 |
Correct |
120 ms |
128160 KB |
Output is correct |
21 |
Correct |
104 ms |
128088 KB |
Output is correct |
22 |
Correct |
100 ms |
128156 KB |
Output is correct |
23 |
Correct |
101 ms |
128120 KB |
Output is correct |
24 |
Correct |
103 ms |
128120 KB |
Output is correct |
25 |
Correct |
102 ms |
128120 KB |
Output is correct |
26 |
Correct |
101 ms |
128120 KB |
Output is correct |
27 |
Correct |
101 ms |
127992 KB |
Output is correct |
28 |
Correct |
101 ms |
128120 KB |
Output is correct |
29 |
Correct |
105 ms |
128120 KB |
Output is correct |
30 |
Correct |
102 ms |
128220 KB |
Output is correct |
31 |
Correct |
103 ms |
128092 KB |
Output is correct |
32 |
Correct |
103 ms |
128120 KB |
Output is correct |
33 |
Correct |
104 ms |
128128 KB |
Output is correct |
34 |
Correct |
122 ms |
128032 KB |
Output is correct |
35 |
Correct |
106 ms |
128120 KB |
Output is correct |
36 |
Correct |
104 ms |
128120 KB |
Output is correct |
37 |
Correct |
104 ms |
128108 KB |
Output is correct |
38 |
Correct |
100 ms |
128120 KB |
Output is correct |
39 |
Correct |
105 ms |
128124 KB |
Output is correct |
40 |
Correct |
102 ms |
128120 KB |
Output is correct |
41 |
Correct |
102 ms |
128124 KB |
Output is correct |
42 |
Correct |
104 ms |
128120 KB |
Output is correct |
43 |
Correct |
592 ms |
129472 KB |
Output is correct |
44 |
Incorrect |
3164 ms |
138004 KB |
Integer parameter [name=A_i] equals to -2299183645602024562, violates the range [1, 2000000000000] |
45 |
Halted |
0 ms |
0 KB |
- |