# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535204 |
2022-03-09T16:52:57 Z |
pooyashams |
Naan (JOI19_naan) |
C++17 |
|
782 ms |
131832 KB |
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
using namespace std;
typedef long long ll;
#define int ll
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 2012;
struct mfint
{
ll a, b; // a/b
mfint()
{
a = 1;
b = 1;
};
mfint(ll _a, ll _b)
{
a = _a;
b = _b;
ll x = gcd(a, b);
a /= x;
b /= x;
}
inline bool operator<(const mfint &o) const
{
return 1.0l*a*o.b < 1.0l*o.a*b;
}
};
int vals[maxn][maxn];
int ps[maxn][maxn];
mfint blues[maxn][maxn];
int f;
ll n, L;
inline void prn(mfint a)
{
cerr << a.a << "/" << a.b << " ";
}
//inline int cmp(int i, int j)
//{
// return blues[i][f] < blues[j][f];
//}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> L;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < L; j++)
{
cin >> vals[i][j];
ps[i][j+1] = ps[i][j]+vals[i][j];
}
}
for(int i = 0; i < n; i++)
{
int p = 0;
ll s = ps[i][L];
for(int j = 1; j <= n; j++)
{
while( (n*(ps[i][p] + vals[i][p])) < s*j )
p++;
blues[i][j-1] = mfint(s*j-n*ps[i][p] + n*vals[i][p]*p, n*vals[i][p]);
//prn(blues[i][j]);
}
}
vector<int> rem(n);
iota(rem.begin(), rem.end(), 0);
vector<int> prm;
vector<mfint> mfs;
for(int f = 0; f < n; f++)
{
int mnidx = min_element(rem.begin(), rem.end(), [&](int i, int j){ return blues[i][f] < blues[j][f];}) - rem.begin();
//cerr << rem[mnidx] << endl;
prm.push_back(rem[mnidx]);
mfs.push_back(blues[rem[mnidx]][f]);
rem.erase(rem.begin()+mnidx);
}
mfs.pop_back();
for(mfint m: mfs)
cout << m.a << " " << m.b << endl;
for(int x: prm)
cout << x+1 << " ";
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
63692 KB |
Output is correct |
2 |
Correct |
30 ms |
63636 KB |
Output is correct |
3 |
Correct |
38 ms |
63692 KB |
Output is correct |
4 |
Correct |
34 ms |
63772 KB |
Output is correct |
5 |
Correct |
32 ms |
63676 KB |
Output is correct |
6 |
Correct |
28 ms |
63696 KB |
Output is correct |
7 |
Correct |
33 ms |
63692 KB |
Output is correct |
8 |
Correct |
31 ms |
63684 KB |
Output is correct |
9 |
Correct |
42 ms |
63704 KB |
Output is correct |
10 |
Correct |
31 ms |
63692 KB |
Output is correct |
11 |
Correct |
30 ms |
63708 KB |
Output is correct |
12 |
Correct |
39 ms |
63748 KB |
Output is correct |
13 |
Correct |
32 ms |
63656 KB |
Output is correct |
14 |
Correct |
30 ms |
63692 KB |
Output is correct |
15 |
Correct |
37 ms |
63684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
63688 KB |
Output is correct |
2 |
Correct |
30 ms |
63704 KB |
Output is correct |
3 |
Correct |
28 ms |
63812 KB |
Output is correct |
4 |
Correct |
35 ms |
63812 KB |
Output is correct |
5 |
Correct |
28 ms |
63820 KB |
Output is correct |
6 |
Correct |
29 ms |
63760 KB |
Output is correct |
7 |
Correct |
31 ms |
63736 KB |
Output is correct |
8 |
Correct |
30 ms |
63696 KB |
Output is correct |
9 |
Correct |
35 ms |
63816 KB |
Output is correct |
10 |
Correct |
35 ms |
63816 KB |
Output is correct |
11 |
Correct |
29 ms |
63764 KB |
Output is correct |
12 |
Correct |
28 ms |
63732 KB |
Output is correct |
13 |
Correct |
29 ms |
63780 KB |
Output is correct |
14 |
Correct |
38 ms |
63812 KB |
Output is correct |
15 |
Correct |
30 ms |
63760 KB |
Output is correct |
16 |
Correct |
34 ms |
63812 KB |
Output is correct |
17 |
Correct |
32 ms |
63876 KB |
Output is correct |
18 |
Correct |
32 ms |
63816 KB |
Output is correct |
19 |
Correct |
35 ms |
63784 KB |
Output is correct |
20 |
Correct |
30 ms |
63776 KB |
Output is correct |
21 |
Correct |
32 ms |
63800 KB |
Output is correct |
22 |
Correct |
31 ms |
63904 KB |
Output is correct |
23 |
Correct |
32 ms |
63672 KB |
Output is correct |
24 |
Correct |
40 ms |
63816 KB |
Output is correct |
25 |
Correct |
33 ms |
63708 KB |
Output is correct |
26 |
Correct |
37 ms |
63712 KB |
Output is correct |
27 |
Correct |
33 ms |
63780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
63692 KB |
Output is correct |
2 |
Correct |
30 ms |
63636 KB |
Output is correct |
3 |
Correct |
38 ms |
63692 KB |
Output is correct |
4 |
Correct |
34 ms |
63772 KB |
Output is correct |
5 |
Correct |
32 ms |
63676 KB |
Output is correct |
6 |
Correct |
28 ms |
63696 KB |
Output is correct |
7 |
Correct |
33 ms |
63692 KB |
Output is correct |
8 |
Correct |
31 ms |
63684 KB |
Output is correct |
9 |
Correct |
42 ms |
63704 KB |
Output is correct |
10 |
Correct |
31 ms |
63692 KB |
Output is correct |
11 |
Correct |
30 ms |
63708 KB |
Output is correct |
12 |
Correct |
39 ms |
63748 KB |
Output is correct |
13 |
Correct |
32 ms |
63656 KB |
Output is correct |
14 |
Correct |
30 ms |
63692 KB |
Output is correct |
15 |
Correct |
37 ms |
63684 KB |
Output is correct |
16 |
Correct |
30 ms |
63688 KB |
Output is correct |
17 |
Correct |
30 ms |
63704 KB |
Output is correct |
18 |
Correct |
28 ms |
63812 KB |
Output is correct |
19 |
Correct |
35 ms |
63812 KB |
Output is correct |
20 |
Correct |
28 ms |
63820 KB |
Output is correct |
21 |
Correct |
29 ms |
63760 KB |
Output is correct |
22 |
Correct |
31 ms |
63736 KB |
Output is correct |
23 |
Correct |
30 ms |
63696 KB |
Output is correct |
24 |
Correct |
35 ms |
63816 KB |
Output is correct |
25 |
Correct |
35 ms |
63816 KB |
Output is correct |
26 |
Correct |
29 ms |
63764 KB |
Output is correct |
27 |
Correct |
28 ms |
63732 KB |
Output is correct |
28 |
Correct |
29 ms |
63780 KB |
Output is correct |
29 |
Correct |
38 ms |
63812 KB |
Output is correct |
30 |
Correct |
30 ms |
63760 KB |
Output is correct |
31 |
Correct |
34 ms |
63812 KB |
Output is correct |
32 |
Correct |
32 ms |
63876 KB |
Output is correct |
33 |
Correct |
32 ms |
63816 KB |
Output is correct |
34 |
Correct |
35 ms |
63784 KB |
Output is correct |
35 |
Correct |
30 ms |
63776 KB |
Output is correct |
36 |
Correct |
32 ms |
63800 KB |
Output is correct |
37 |
Correct |
31 ms |
63904 KB |
Output is correct |
38 |
Correct |
32 ms |
63672 KB |
Output is correct |
39 |
Correct |
40 ms |
63816 KB |
Output is correct |
40 |
Correct |
33 ms |
63708 KB |
Output is correct |
41 |
Correct |
37 ms |
63712 KB |
Output is correct |
42 |
Correct |
33 ms |
63780 KB |
Output is correct |
43 |
Correct |
94 ms |
73752 KB |
Output is correct |
44 |
Correct |
414 ms |
104832 KB |
Output is correct |
45 |
Correct |
221 ms |
89408 KB |
Output is correct |
46 |
Correct |
49 ms |
68516 KB |
Output is correct |
47 |
Correct |
286 ms |
97564 KB |
Output is correct |
48 |
Correct |
506 ms |
94100 KB |
Output is correct |
49 |
Correct |
145 ms |
79720 KB |
Output is correct |
50 |
Correct |
658 ms |
123492 KB |
Output is correct |
51 |
Correct |
281 ms |
100192 KB |
Output is correct |
52 |
Correct |
571 ms |
121900 KB |
Output is correct |
53 |
Correct |
527 ms |
116960 KB |
Output is correct |
54 |
Correct |
33 ms |
63812 KB |
Output is correct |
55 |
Correct |
263 ms |
77636 KB |
Output is correct |
56 |
Correct |
331 ms |
108776 KB |
Output is correct |
57 |
Correct |
294 ms |
103040 KB |
Output is correct |
58 |
Correct |
460 ms |
112216 KB |
Output is correct |
59 |
Correct |
291 ms |
103020 KB |
Output is correct |
60 |
Correct |
673 ms |
130856 KB |
Output is correct |
61 |
Correct |
693 ms |
130676 KB |
Output is correct |
62 |
Correct |
782 ms |
130592 KB |
Output is correct |
63 |
Correct |
754 ms |
130724 KB |
Output is correct |
64 |
Correct |
710 ms |
130844 KB |
Output is correct |
65 |
Correct |
759 ms |
131560 KB |
Output is correct |
66 |
Correct |
745 ms |
131832 KB |
Output is correct |
67 |
Correct |
657 ms |
131788 KB |
Output is correct |
68 |
Correct |
321 ms |
105556 KB |
Output is correct |
69 |
Correct |
303 ms |
107748 KB |
Output is correct |
70 |
Correct |
364 ms |
109220 KB |
Output is correct |
71 |
Correct |
440 ms |
118432 KB |
Output is correct |