답안 #738017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
738017 2023-05-08T05:30:00 Z maomao90 Self Study (JOI22_ho_t2) C++17
100 / 100
267 ms 10912 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 2000000000000000005ll;
const int MAXN = 300005;

int n, m;
int a[MAXN], b[MAXN];

ll need[MAXN];
bool isPos(ll x) {
    ll ex = 0;
    REP (i, 0, n) {
        need[i] = x;
        if (a[i] <= b[i]) {
            ex += m;
            continue;
        }
        ll use = min((ll) m, (x - 1) / a[i] + 1);
        ex += m - use;
        need[i] = max(0ll, x - use * a[i]);
    }
    REP (i, 0, n) {
        if (need[i] == 0) {
            continue;
        }
        ll use = (need[i] - 1) / b[i] + 1;
        ex -= use;
        if (ex < 0) {
            return 0;
        }
    }
    return ex >= 0;
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> m;
    REP (i, 0, n) {
        cin >> a[i];
    }
    REP (i, 0, n) {
        cin >> b[i];
    }
    ll lo = 0, hi = LINF, mid;
    while (lo < hi) {
        mid = lo + hi + 1 >> 1;
        if (isPos(mid)) {
            lo = mid;
        } else {
            hi = mid - 1;
        }
    }
    cout << lo << '\n';
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:80:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |         mid = lo + hi + 1 >> 1;
      |               ~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 200 ms 4920 KB Output is correct
12 Correct 199 ms 4996 KB Output is correct
13 Correct 97 ms 5000 KB Output is correct
14 Correct 156 ms 5108 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 43 ms 5016 KB Output is correct
17 Correct 112 ms 4928 KB Output is correct
18 Correct 109 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 43 ms 5016 KB Output is correct
3 Correct 112 ms 4928 KB Output is correct
4 Correct 109 ms 4984 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 56 ms 2584 KB Output is correct
14 Correct 35 ms 1796 KB Output is correct
15 Correct 27 ms 1516 KB Output is correct
16 Correct 22 ms 1272 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 200 ms 4920 KB Output is correct
12 Correct 199 ms 4996 KB Output is correct
13 Correct 97 ms 5000 KB Output is correct
14 Correct 156 ms 5108 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 56 ms 2584 KB Output is correct
24 Correct 35 ms 1796 KB Output is correct
25 Correct 27 ms 1516 KB Output is correct
26 Correct 22 ms 1272 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 4 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 43 ms 5016 KB Output is correct
36 Correct 112 ms 4928 KB Output is correct
37 Correct 109 ms 4984 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 4 ms 468 KB Output is correct
46 Correct 7 ms 596 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 34 ms 2132 KB Output is correct
49 Correct 1 ms 324 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 4 ms 468 KB Output is correct
52 Correct 1 ms 324 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 101 ms 5420 KB Output is correct
56 Correct 37 ms 3168 KB Output is correct
57 Correct 62 ms 3032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 56 ms 2584 KB Output is correct
10 Correct 35 ms 1796 KB Output is correct
11 Correct 27 ms 1516 KB Output is correct
12 Correct 22 ms 1272 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 43 ms 5016 KB Output is correct
22 Correct 112 ms 4928 KB Output is correct
23 Correct 109 ms 4984 KB Output is correct
24 Correct 34 ms 960 KB Output is correct
25 Correct 77 ms 2364 KB Output is correct
26 Correct 14 ms 724 KB Output is correct
27 Correct 107 ms 5100 KB Output is correct
28 Correct 109 ms 5004 KB Output is correct
29 Correct 111 ms 4944 KB Output is correct
30 Correct 143 ms 4948 KB Output is correct
31 Correct 211 ms 5000 KB Output is correct
32 Correct 130 ms 4948 KB Output is correct
33 Correct 257 ms 5000 KB Output is correct
34 Correct 126 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 200 ms 4920 KB Output is correct
12 Correct 199 ms 4996 KB Output is correct
13 Correct 97 ms 5000 KB Output is correct
14 Correct 156 ms 5108 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 56 ms 2584 KB Output is correct
24 Correct 35 ms 1796 KB Output is correct
25 Correct 27 ms 1516 KB Output is correct
26 Correct 22 ms 1272 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 4 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 4 ms 468 KB Output is correct
42 Correct 7 ms 596 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 34 ms 2132 KB Output is correct
45 Correct 1 ms 324 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 4 ms 468 KB Output is correct
48 Correct 1 ms 324 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 101 ms 5420 KB Output is correct
52 Correct 37 ms 3168 KB Output is correct
53 Correct 62 ms 3032 KB Output is correct
54 Correct 34 ms 960 KB Output is correct
55 Correct 77 ms 2364 KB Output is correct
56 Correct 14 ms 724 KB Output is correct
57 Correct 107 ms 5100 KB Output is correct
58 Correct 109 ms 5004 KB Output is correct
59 Correct 111 ms 4944 KB Output is correct
60 Correct 143 ms 4948 KB Output is correct
61 Correct 211 ms 5000 KB Output is correct
62 Correct 130 ms 4948 KB Output is correct
63 Correct 257 ms 5000 KB Output is correct
64 Correct 126 ms 4940 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 43 ms 5016 KB Output is correct
67 Correct 112 ms 4928 KB Output is correct
68 Correct 109 ms 4984 KB Output is correct
69 Correct 31 ms 1452 KB Output is correct
70 Correct 7 ms 540 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 38 ms 1748 KB Output is correct
73 Correct 8 ms 596 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 205 ms 10796 KB Output is correct
76 Correct 218 ms 10788 KB Output is correct
77 Correct 213 ms 10912 KB Output is correct
78 Correct 241 ms 10776 KB Output is correct
79 Correct 251 ms 10792 KB Output is correct
80 Correct 267 ms 10796 KB Output is correct
81 Correct 241 ms 8712 KB Output is correct
82 Correct 249 ms 8728 KB Output is correct