# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057712 |
2024-08-14T03:57:32 Z |
hotboy2703 |
Naan (JOI19_naan) |
C++17 |
|
221 ms |
123220 KB |
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 2e3+100;
const ll INF = 1e18;
ll n,L;
ll v[MAXN][MAXN];
pll cut[MAXN][MAXN];
bool in[MAXN];
ll p[MAXN];
pll sus[MAXN];
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);
cin>>n>>L;
for (ll i = 1;i <= n; i++){
ll sum = 0;
for (ll j = 1;j <= L;j ++){
cin>>v[i][j];
v[i][j] *= n;
sum += v[i][j];
}
sum /= n;
ll A = 0,B = 1;
for (ll j = 1;j <= n;j ++){
ll cur = 0;
while (cur < sum && (B-A%B) * v[i][A/B+1] / B + cur <= sum)cur+=(B-A%B) * v[i][A/B+1] / B,A+=(B-A%B),A/=B,B=1;
if (cur < sum){
if (B==1){
B=v[i][A/B+1];
A *= B;
}
A += (sum - cur);
cur = sum;
}
// assert(cur==sum);
cut[i][j] = MP(A,B);
// assert(B<=1e9);
// if (j>1)if(cut[i][j].fi * cut[i][j-1].se <= cut[i][j-1].fi * cut[i][j].se){
// cout<<cut[i][j-1].fi<<' '<<cut[i][j-1].se<<' '<<cut[i][j].fi<<' '<<cut[i][j].se<<'\n';
// return 0;
// }
// cout<<A<<' '<<B<<endl;
}
}
for (ll i = 1; i<= n;i ++)in[i] = 1;
for (ll j = 1;j <= n;j ++){
ll best = -1;
for (ll i = 1;i <= n;i ++){
if (in[i] == 1){
if (best==-1)best = i;
else{
ll a1 = cut[best][j].fi,b1 = cut[best][j].se;
ll a2 = cut[i][j].fi,b2 = cut[i][j].se;
if (__int128_t(a1)*b2>__int128_t(a2)*b1)best = i;
}
}
}
in[best] = 0;
p[j]=best;
sus[j] = cut[best][j];
}
for (ll j = 1;j <= n-1;j ++){
cout<<sus[j].fi<<' '<<sus[j].se<<'\n';
}
for (ll j = 1;j <= n;j ++)cout<<p[j]<<' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
2 ms |
4440 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
0 ms |
4444 KB |
Output is correct |
28 |
Correct |
0 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
2 ms |
4440 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
0 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
17 ms |
31320 KB |
Output is correct |
44 |
Correct |
100 ms |
70224 KB |
Output is correct |
45 |
Correct |
79 ms |
44820 KB |
Output is correct |
46 |
Correct |
12 ms |
9820 KB |
Output is correct |
47 |
Correct |
78 ms |
59824 KB |
Output is correct |
48 |
Correct |
56 ms |
96820 KB |
Output is correct |
49 |
Correct |
24 ms |
46672 KB |
Output is correct |
50 |
Correct |
113 ms |
106608 KB |
Output is correct |
51 |
Correct |
65 ms |
57428 KB |
Output is correct |
52 |
Correct |
127 ms |
95672 KB |
Output is correct |
53 |
Correct |
95 ms |
91476 KB |
Output is correct |
54 |
Correct |
1 ms |
4444 KB |
Output is correct |
55 |
Correct |
23 ms |
72668 KB |
Output is correct |
56 |
Correct |
82 ms |
70484 KB |
Output is correct |
57 |
Correct |
66 ms |
67416 KB |
Output is correct |
58 |
Correct |
91 ms |
92500 KB |
Output is correct |
59 |
Correct |
75 ms |
62036 KB |
Output is correct |
60 |
Correct |
218 ms |
122944 KB |
Output is correct |
61 |
Correct |
220 ms |
122964 KB |
Output is correct |
62 |
Correct |
221 ms |
123064 KB |
Output is correct |
63 |
Correct |
221 ms |
123220 KB |
Output is correct |
64 |
Correct |
215 ms |
122964 KB |
Output is correct |
65 |
Correct |
166 ms |
109652 KB |
Output is correct |
66 |
Correct |
189 ms |
109648 KB |
Output is correct |
67 |
Correct |
162 ms |
109652 KB |
Output is correct |
68 |
Correct |
81 ms |
78164 KB |
Output is correct |
69 |
Correct |
98 ms |
71876 KB |
Output is correct |
70 |
Correct |
91 ms |
88984 KB |
Output is correct |
71 |
Correct |
137 ms |
93524 KB |
Output is correct |