# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
947668 |
2024-03-16T18:36:18 Z |
veljko |
Self Study (JOI22_ho_t2) |
C++17 |
|
233 ms |
29144 KB |
/*****from dust I have come, dust I will be*****/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define forn(i,n) for(int i=0;i<n;i++)
int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int ceil_div(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}
const int MOD = 1000000007;
//const int MOD = 998244353;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
/*
int k = A.order_of_key(p[i].second);
A.erase(A.find_by_order(k));
erase element from pbds multiset
*/
bool ok(vector<int>&a, int n, int v, int target){
forn(i,n){
int x = ceil_div(target, a[i]);
//cout <<x<<'\n';
v -= x;
if (v < 0) return false;
}
return (v >= 0);
}
int binary(vector<int>&a, int n, int v){
int l = 0, r = 5 * 1e18;
int ans = 0;
while (l <= r){
int mid = (l + r) / 2;
if (ok(a, n, v, mid)){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
return ans;
}
bool ok2(vector<pair<pair<int, int>, pair<int, int>>>&skup, int target, int u, int m){
int tmp = target;
forn(i,(int)skup.size()){
target = tmp;
if (u < 0) return false;
auto v = skup[i];
//cout <<v.first.first<<' '<<v.first.second<<'\n';
if (v.first.first >= target) break;
if (v.second.second >= v.second.first){
int x = ceil_div(target, v.second.second);
v.first.first += (v.second.second * x);
u -= x;
}
else{
int y = m - v.first.second; //koliko mozemo
int potrebno = ceil_div(target, v.second.first); //koliko je potrebno
if (potrebno <= y){
v.first.second += potrebno;
v.first.first += (v.second.first * potrebno); //dodaj v
u -= potrebno;
}
else{
v.first.second = m;
target -= y * v.second.first;
v.first.first += y * v.second.first;
u -= y;
potrebno = ceil_div(target, v.second.second);
v.first.first += (v.second.second * potrebno);
u -= potrebno;
}
}
//cout <<v.first.first<<' '<<v.first.second<<' '<<v.second.first<<' '<<v.second.second<<'\n';
}
//cout <<u<<'\n';
return (u >= 0);
}
int binary2(vector<pair<pair<int, int>, pair<int, int>>>&skup, int n, int m){
int l = 0,r = 1e18;
int ans = 0;
while (l <= r){
int mid = (l + r) / 2;
if (ok2(skup, mid, n*m, m)){
ans = mid;
l = mid + 1;
}
else r= mid - 1;
}
return ans;
}
void solve(){
int n, m; cin >> n >> m;
vector<int>a(n); for (auto &t : a) cin >> t;
vector<int>b(n); for (auto &t : b) cin >> t;
if (a == b) cout << binary(a, n, n*m)<<'\n';
else{
vector<pair<pair<int, int>, pair<int, int>>>skup;
forn(i,n) skup.push_back({{0, 0}, {a[i], b[i]}});
sort(skup.begin(), skup.end());
cout <<binary2(skup,n,m)<<'\n';
}
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1; //cin >>t;
for (int i=1;i<=t;i++){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
120 ms |
23172 KB |
Output is correct |
12 |
Correct |
117 ms |
22980 KB |
Output is correct |
13 |
Correct |
85 ms |
23664 KB |
Output is correct |
14 |
Correct |
76 ms |
21700 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
26 ms |
5116 KB |
Output is correct |
17 |
Correct |
93 ms |
5108 KB |
Output is correct |
18 |
Correct |
79 ms |
5144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
26 ms |
5116 KB |
Output is correct |
3 |
Correct |
93 ms |
5108 KB |
Output is correct |
4 |
Correct |
79 ms |
5144 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
356 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
42 ms |
2792 KB |
Output is correct |
14 |
Correct |
27 ms |
1884 KB |
Output is correct |
15 |
Correct |
20 ms |
1628 KB |
Output is correct |
16 |
Correct |
17 ms |
1372 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
120 ms |
23172 KB |
Output is correct |
12 |
Correct |
117 ms |
22980 KB |
Output is correct |
13 |
Correct |
85 ms |
23664 KB |
Output is correct |
14 |
Correct |
76 ms |
21700 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
356 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
42 ms |
2792 KB |
Output is correct |
24 |
Correct |
27 ms |
1884 KB |
Output is correct |
25 |
Correct |
20 ms |
1628 KB |
Output is correct |
26 |
Correct |
17 ms |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
26 ms |
5116 KB |
Output is correct |
36 |
Correct |
93 ms |
5108 KB |
Output is correct |
37 |
Correct |
79 ms |
5144 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
860 KB |
Output is correct |
46 |
Correct |
4 ms |
1240 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
21 ms |
3288 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
2 ms |
860 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
59 ms |
12244 KB |
Output is correct |
56 |
Correct |
31 ms |
7376 KB |
Output is correct |
57 |
Correct |
26 ms |
6868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
356 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
42 ms |
2792 KB |
Output is correct |
10 |
Correct |
27 ms |
1884 KB |
Output is correct |
11 |
Correct |
20 ms |
1628 KB |
Output is correct |
12 |
Correct |
17 ms |
1372 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
26 ms |
5116 KB |
Output is correct |
22 |
Correct |
93 ms |
5108 KB |
Output is correct |
23 |
Correct |
79 ms |
5144 KB |
Output is correct |
24 |
Correct |
26 ms |
1116 KB |
Output is correct |
25 |
Correct |
61 ms |
2396 KB |
Output is correct |
26 |
Correct |
10 ms |
860 KB |
Output is correct |
27 |
Correct |
79 ms |
5140 KB |
Output is correct |
28 |
Correct |
83 ms |
4956 KB |
Output is correct |
29 |
Correct |
85 ms |
5124 KB |
Output is correct |
30 |
Correct |
109 ms |
5144 KB |
Output is correct |
31 |
Correct |
181 ms |
4956 KB |
Output is correct |
32 |
Correct |
107 ms |
4952 KB |
Output is correct |
33 |
Correct |
209 ms |
4948 KB |
Output is correct |
34 |
Correct |
112 ms |
5140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
120 ms |
23172 KB |
Output is correct |
12 |
Correct |
117 ms |
22980 KB |
Output is correct |
13 |
Correct |
85 ms |
23664 KB |
Output is correct |
14 |
Correct |
76 ms |
21700 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
356 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
42 ms |
2792 KB |
Output is correct |
24 |
Correct |
27 ms |
1884 KB |
Output is correct |
25 |
Correct |
20 ms |
1628 KB |
Output is correct |
26 |
Correct |
17 ms |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
3 ms |
860 KB |
Output is correct |
42 |
Correct |
4 ms |
1240 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
21 ms |
3288 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
2 ms |
860 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
59 ms |
12244 KB |
Output is correct |
52 |
Correct |
31 ms |
7376 KB |
Output is correct |
53 |
Correct |
26 ms |
6868 KB |
Output is correct |
54 |
Correct |
26 ms |
1116 KB |
Output is correct |
55 |
Correct |
61 ms |
2396 KB |
Output is correct |
56 |
Correct |
10 ms |
860 KB |
Output is correct |
57 |
Correct |
79 ms |
5140 KB |
Output is correct |
58 |
Correct |
83 ms |
4956 KB |
Output is correct |
59 |
Correct |
85 ms |
5124 KB |
Output is correct |
60 |
Correct |
109 ms |
5144 KB |
Output is correct |
61 |
Correct |
181 ms |
4956 KB |
Output is correct |
62 |
Correct |
107 ms |
4952 KB |
Output is correct |
63 |
Correct |
209 ms |
4948 KB |
Output is correct |
64 |
Correct |
112 ms |
5140 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
26 ms |
5116 KB |
Output is correct |
67 |
Correct |
93 ms |
5108 KB |
Output is correct |
68 |
Correct |
79 ms |
5144 KB |
Output is correct |
69 |
Correct |
22 ms |
2012 KB |
Output is correct |
70 |
Correct |
7 ms |
1016 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
33 ms |
4116 KB |
Output is correct |
73 |
Correct |
7 ms |
1240 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
124 ms |
27784 KB |
Output is correct |
76 |
Correct |
136 ms |
28624 KB |
Output is correct |
77 |
Correct |
146 ms |
29144 KB |
Output is correct |
78 |
Correct |
178 ms |
28612 KB |
Output is correct |
79 |
Correct |
230 ms |
29140 KB |
Output is correct |
80 |
Correct |
233 ms |
27844 KB |
Output is correct |
81 |
Correct |
213 ms |
26316 KB |
Output is correct |
82 |
Correct |
213 ms |
27264 KB |
Output is correct |