Submission #534153

# Submission time Handle Problem Language Result Execution time Memory
534153 2022-03-08T01:41:11 Z Cookie197 Self Study (JOI22_ho_t2) C++14
100 / 100
261 ms 10632 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll> 
#define mp make_pair
#define endl "\n"
#define out(x) cout << #x << " = " << x << endl
#define outp(x) cout << #x << ".first = " << x.first << "  " << #x << ".second = " << x.second << endl
#pragma GCC optimize("Ofast")
#define lll __int128

ll n,m;
ll a[300005],b[300005];
signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) { ll x; cin>>x; a[i] = x;}
    for (int i=1;i<=n;i++) { ll x; cin>>x; b[i] = x; a[i] = max(a[i], b[i]);}
    if (m==1){
        ll ans = 1e18;
        for (int i=1;i<=n;i++) ans = min(ans, max(a[i],b[i]));
        cout<<(ll)ans<<endl;
        return 0;
    }

    ll arr[n+2], remain[n+2];  // 目前學分,這個位置剩下幾堂課
    ll left = 0, right = 2e18, mid = (left+right)/2;
    while(left<right){
        mid = (left+right)/2;
        ll rem=0;
        int flag=true;
        for (int i=1;i<=n;i++) {
            if (a[i] * m < mid) {
                arr[i] = a[i] * m;
            }else{
                ll use = (mid-1)/a[i] + 1;
                rem += m - use;
                arr[i] = use * a[i];
            }
        }
        //cout<<mid<<"  "<<rem<<endl;
        for (int i=1;i<=n;i++) if (arr[i]<mid){
            ll need = (mid-arr[i]-1) / b[i] + 1;
            rem -= need;
            if (rem<0) {flag=false; break;}
        }
        if (flag) left=mid+1;
        else right=mid;
    }
    cout<<(ll)left-1<<endl;

}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:29:18: warning: unused variable 'remain' [-Wunused-variable]
   29 |     ll arr[n+2], remain[n+2];  // 目前學分,這個位置剩下幾堂課
      |                  ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 55 ms 4988 KB Output is correct
12 Correct 54 ms 4868 KB Output is correct
13 Correct 51 ms 4968 KB Output is correct
14 Correct 54 ms 4916 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 29 ms 5796 KB Output is correct
17 Correct 73 ms 6540 KB Output is correct
18 Correct 59 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 29 ms 5796 KB Output is correct
3 Correct 73 ms 6540 KB Output is correct
4 Correct 59 ms 6492 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 64 ms 4880 KB Output is correct
14 Correct 48 ms 3524 KB Output is correct
15 Correct 32 ms 2808 KB Output is correct
16 Correct 26 ms 2440 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 320 KB Output is correct
22 Correct 1 ms 376 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 55 ms 4988 KB Output is correct
12 Correct 54 ms 4868 KB Output is correct
13 Correct 51 ms 4968 KB Output is correct
14 Correct 54 ms 4916 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 64 ms 4880 KB Output is correct
24 Correct 48 ms 3524 KB Output is correct
25 Correct 32 ms 2808 KB Output is correct
26 Correct 26 ms 2440 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 320 KB Output is correct
32 Correct 1 ms 376 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 1 ms 316 KB Output is correct
35 Correct 29 ms 5796 KB Output is correct
36 Correct 73 ms 6540 KB Output is correct
37 Correct 59 ms 6492 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 4 ms 588 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 22 ms 2252 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 4 ms 428 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 61 ms 6332 KB Output is correct
56 Correct 36 ms 3688 KB Output is correct
57 Correct 37 ms 3768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 64 ms 4880 KB Output is correct
10 Correct 48 ms 3524 KB Output is correct
11 Correct 32 ms 2808 KB Output is correct
12 Correct 26 ms 2440 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 29 ms 5796 KB Output is correct
22 Correct 73 ms 6540 KB Output is correct
23 Correct 59 ms 6492 KB Output is correct
24 Correct 36 ms 2128 KB Output is correct
25 Correct 83 ms 5280 KB Output is correct
26 Correct 16 ms 1604 KB Output is correct
27 Correct 125 ms 8896 KB Output is correct
28 Correct 131 ms 8900 KB Output is correct
29 Correct 131 ms 8984 KB Output is correct
30 Correct 151 ms 8768 KB Output is correct
31 Correct 235 ms 8388 KB Output is correct
32 Correct 95 ms 8264 KB Output is correct
33 Correct 99 ms 8980 KB Output is correct
34 Correct 95 ms 8504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 55 ms 4988 KB Output is correct
12 Correct 54 ms 4868 KB Output is correct
13 Correct 51 ms 4968 KB Output is correct
14 Correct 54 ms 4916 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 64 ms 4880 KB Output is correct
24 Correct 48 ms 3524 KB Output is correct
25 Correct 32 ms 2808 KB Output is correct
26 Correct 26 ms 2440 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 320 KB Output is correct
32 Correct 1 ms 376 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 3 ms 460 KB Output is correct
42 Correct 4 ms 588 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 22 ms 2252 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 4 ms 428 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 61 ms 6332 KB Output is correct
52 Correct 36 ms 3688 KB Output is correct
53 Correct 37 ms 3768 KB Output is correct
54 Correct 36 ms 2128 KB Output is correct
55 Correct 83 ms 5280 KB Output is correct
56 Correct 16 ms 1604 KB Output is correct
57 Correct 125 ms 8896 KB Output is correct
58 Correct 131 ms 8900 KB Output is correct
59 Correct 131 ms 8984 KB Output is correct
60 Correct 151 ms 8768 KB Output is correct
61 Correct 235 ms 8388 KB Output is correct
62 Correct 95 ms 8264 KB Output is correct
63 Correct 99 ms 8980 KB Output is correct
64 Correct 95 ms 8504 KB Output is correct
65 Correct 1 ms 316 KB Output is correct
66 Correct 29 ms 5796 KB Output is correct
67 Correct 73 ms 6540 KB Output is correct
68 Correct 59 ms 6492 KB Output is correct
69 Correct 24 ms 1608 KB Output is correct
70 Correct 7 ms 560 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 35 ms 2116 KB Output is correct
73 Correct 8 ms 716 KB Output is correct
74 Correct 1 ms 324 KB Output is correct
75 Correct 126 ms 10556 KB Output is correct
76 Correct 140 ms 10436 KB Output is correct
77 Correct 160 ms 10632 KB Output is correct
78 Correct 178 ms 10436 KB Output is correct
79 Correct 244 ms 10512 KB Output is correct
80 Correct 261 ms 10556 KB Output is correct
81 Correct 77 ms 10436 KB Output is correct
82 Correct 76 ms 10508 KB Output is correct