# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
162935 |
2019-11-10T10:20:55 Z |
combi1k1 |
Naan (JOI19_naan) |
C++14 |
|
734 ms |
112568 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define FOR(i,a,b) for(int i = a ; i < b ; ++i)
const int N = 2e3 + 1;
const int inf = 1e9 + 7;
struct Frac {
ll int_part;
ll upper;
ll lower;
Frac(ll a = 0,ll b = 0,ll c = 0) {
int_part = a;
upper = b;
lower = c;
if (b > c) {
int_part += b / c;
upper %= c;
}
if (c < 0)
upper *= (-1),
lower *= (-1);
};
};
bool operator < (const Frac &lhs,const Frac &rhs) {
if (lhs.int_part != rhs.int_part)
return lhs.int_part < rhs.int_part;
return lhs.upper * rhs.lower < lhs.lower * rhs.upper;
}
ostream & operator << (ostream &out,Frac &C) {
ll g = __gcd(C.upper,C.lower);
C.upper /= g;
C.lower /= g;
ll a = C.int_part * C.lower + C.upper;
ll b = C.lower;
out << a << " ";
out << b << "\n";
return out;
}
int v[N][N];
ll s[N];
vector<Frac> cut[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int L; cin >> L;
FOR(i,0,n) FOR(j,0,L) {
cin >> v[i][j];
s[i] += v[i][j];
}
FOR(i,0,n) {
ll sum = 0;
int ptr = 0;
FOR(j,1,n) {
for(; (sum + v[i][ptr]) * n <= s[i] * j ; ++ptr)
sum += v[i][ptr];
ll lower = v[i][ptr] * n;
ll upper = s[i] * j - sum * n;
cut[i].pb({ptr,upper,lower});
}
cut[i].pb({L,0,1});
}
vector<int> perm;
vector<int> have;
FOR(i,0,n) have.push_back(i);
FOR(i,0,n) {
sort(have.begin(),have.end(),[&](int x,int y) {
return cut[y][i] < cut[x][i];
});
perm.push_back(have.back());
have.pop_back();
if (i < n - 1) cout << cut[perm.back()][i];
}
for(int x : perm) cout << x + 1 << " ";
}
/*
2 5
2 7 1 8 2
3 1 4 1 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
14 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
508 KB |
Output is correct |
23 |
Correct |
2 ms |
380 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
380 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
14 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
380 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
3 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
3 ms |
504 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
508 KB |
Output is correct |
38 |
Correct |
2 ms |
380 KB |
Output is correct |
39 |
Correct |
3 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
376 KB |
Output is correct |
43 |
Correct |
62 ms |
13500 KB |
Output is correct |
44 |
Correct |
361 ms |
60580 KB |
Output is correct |
45 |
Correct |
187 ms |
19832 KB |
Output is correct |
46 |
Correct |
24 ms |
1784 KB |
Output is correct |
47 |
Correct |
240 ms |
31728 KB |
Output is correct |
48 |
Correct |
336 ms |
101368 KB |
Output is correct |
49 |
Correct |
95 ms |
26872 KB |
Output is correct |
50 |
Correct |
491 ms |
110840 KB |
Output is correct |
51 |
Correct |
226 ms |
38392 KB |
Output is correct |
52 |
Correct |
462 ms |
89720 KB |
Output is correct |
53 |
Correct |
381 ms |
87092 KB |
Output is correct |
54 |
Correct |
3 ms |
376 KB |
Output is correct |
55 |
Correct |
150 ms |
58744 KB |
Output is correct |
56 |
Correct |
268 ms |
55192 KB |
Output is correct |
57 |
Correct |
220 ms |
49016 KB |
Output is correct |
58 |
Correct |
360 ms |
88612 KB |
Output is correct |
59 |
Correct |
232 ms |
43256 KB |
Output is correct |
60 |
Correct |
677 ms |
112388 KB |
Output is correct |
61 |
Correct |
672 ms |
112568 KB |
Output is correct |
62 |
Correct |
734 ms |
112180 KB |
Output is correct |
63 |
Correct |
704 ms |
112336 KB |
Output is correct |
64 |
Correct |
686 ms |
112544 KB |
Output is correct |
65 |
Correct |
547 ms |
112376 KB |
Output is correct |
66 |
Correct |
542 ms |
112504 KB |
Output is correct |
67 |
Correct |
558 ms |
112476 KB |
Output is correct |
68 |
Correct |
289 ms |
61816 KB |
Output is correct |
69 |
Correct |
286 ms |
51396 KB |
Output is correct |
70 |
Correct |
316 ms |
77212 KB |
Output is correct |
71 |
Correct |
432 ms |
78756 KB |
Output is correct |