답안 #1115902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115902 2024-11-21T03:42:28 Z TrieTr Self Study (JOI22_ho_t2) C++14
100 / 100
133 ms 15176 KB
#include<bits/stdc++.h>
using namespace std;

void local() {
    #define taskname ""
    if (fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
}

#define ll long long
#define int long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;}
template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;}

const int N = 1e6 + 5;

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

bool check(ll x) {
	ll cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] > b[i]) {
			ll useA = min(m * 1ll, (x + a[i] - 1 ) / a[i]);
			ll useB = max(0ll, (x - useA * a[i] + b[i] - 1) / b[i]);
			cnt += useA + useB;		
		}
		else cnt += (x + b[i] - 1) / b[i];
		if(cnt > 1ll * n * m) return false;
	}
	return cnt <= 1ll * n * m;
}

signed main() {
    fastio; local();
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    ll lo = 1, hi = 1e18, res = 0;
	while(lo <= hi) {
		ll mid = (lo + hi) >> 1;
		if(check(mid)) lo = (res = mid) + 1;
		else hi = mid - 1;
	}
	cout << res;
}

Compilation message

Main.cpp: In function 'void local()':
Main.cpp:7:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 80 ms 8840 KB Output is correct
12 Correct 107 ms 8776 KB Output is correct
13 Correct 46 ms 8784 KB Output is correct
14 Correct 53 ms 8660 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 21 ms 8680 KB Output is correct
17 Correct 61 ms 15176 KB Output is correct
18 Correct 61 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 21 ms 8680 KB Output is correct
3 Correct 61 ms 15176 KB Output is correct
4 Correct 61 ms 14412 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2556 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 35 ms 6620 KB Output is correct
14 Correct 24 ms 6736 KB Output is correct
15 Correct 25 ms 6736 KB Output is correct
16 Correct 14 ms 4688 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 2 ms 2384 KB Output is correct
23 Correct 3 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 80 ms 8840 KB Output is correct
12 Correct 107 ms 8776 KB Output is correct
13 Correct 46 ms 8784 KB Output is correct
14 Correct 53 ms 8660 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2552 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2556 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 35 ms 6620 KB Output is correct
24 Correct 24 ms 6736 KB Output is correct
25 Correct 25 ms 6736 KB Output is correct
26 Correct 14 ms 4688 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 2 ms 2384 KB Output is correct
33 Correct 3 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 21 ms 8680 KB Output is correct
36 Correct 61 ms 15176 KB Output is correct
37 Correct 61 ms 14412 KB Output is correct
38 Correct 1 ms 2512 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 2 ms 2384 KB Output is correct
41 Correct 1 ms 2384 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
43 Correct 1 ms 2384 KB Output is correct
44 Correct 1 ms 2556 KB Output is correct
45 Correct 2 ms 2660 KB Output is correct
46 Correct 4 ms 2640 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 17 ms 5704 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 2 ms 2384 KB Output is correct
51 Correct 2 ms 2640 KB Output is correct
52 Correct 1 ms 2384 KB Output is correct
53 Correct 1 ms 2608 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 50 ms 9464 KB Output is correct
56 Correct 21 ms 8016 KB Output is correct
57 Correct 22 ms 8016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2556 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 35 ms 6620 KB Output is correct
10 Correct 24 ms 6736 KB Output is correct
11 Correct 25 ms 6736 KB Output is correct
12 Correct 14 ms 4688 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 2 ms 2384 KB Output is correct
19 Correct 3 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 21 ms 8680 KB Output is correct
22 Correct 61 ms 15176 KB Output is correct
23 Correct 61 ms 14412 KB Output is correct
24 Correct 15 ms 5456 KB Output is correct
25 Correct 41 ms 9296 KB Output is correct
26 Correct 11 ms 5200 KB Output is correct
27 Correct 65 ms 14400 KB Output is correct
28 Correct 97 ms 14408 KB Output is correct
29 Correct 98 ms 14408 KB Output is correct
30 Correct 76 ms 14552 KB Output is correct
31 Correct 92 ms 14456 KB Output is correct
32 Correct 57 ms 9800 KB Output is correct
33 Correct 130 ms 15048 KB Output is correct
34 Correct 45 ms 9808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 80 ms 8840 KB Output is correct
12 Correct 107 ms 8776 KB Output is correct
13 Correct 46 ms 8784 KB Output is correct
14 Correct 53 ms 8660 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2552 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2556 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 35 ms 6620 KB Output is correct
24 Correct 24 ms 6736 KB Output is correct
25 Correct 25 ms 6736 KB Output is correct
26 Correct 14 ms 4688 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 2 ms 2384 KB Output is correct
33 Correct 3 ms 2384 KB Output is correct
34 Correct 1 ms 2512 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 2 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 1 ms 2556 KB Output is correct
41 Correct 2 ms 2660 KB Output is correct
42 Correct 4 ms 2640 KB Output is correct
43 Correct 2 ms 2396 KB Output is correct
44 Correct 17 ms 5704 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 2 ms 2384 KB Output is correct
47 Correct 2 ms 2640 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 1 ms 2608 KB Output is correct
50 Correct 1 ms 2384 KB Output is correct
51 Correct 50 ms 9464 KB Output is correct
52 Correct 21 ms 8016 KB Output is correct
53 Correct 22 ms 8016 KB Output is correct
54 Correct 15 ms 5456 KB Output is correct
55 Correct 41 ms 9296 KB Output is correct
56 Correct 11 ms 5200 KB Output is correct
57 Correct 65 ms 14400 KB Output is correct
58 Correct 97 ms 14408 KB Output is correct
59 Correct 98 ms 14408 KB Output is correct
60 Correct 76 ms 14552 KB Output is correct
61 Correct 92 ms 14456 KB Output is correct
62 Correct 57 ms 9800 KB Output is correct
63 Correct 130 ms 15048 KB Output is correct
64 Correct 45 ms 9808 KB Output is correct
65 Correct 1 ms 2384 KB Output is correct
66 Correct 21 ms 8680 KB Output is correct
67 Correct 61 ms 15176 KB Output is correct
68 Correct 61 ms 14412 KB Output is correct
69 Correct 15 ms 5200 KB Output is correct
70 Correct 4 ms 2640 KB Output is correct
71 Correct 1 ms 2384 KB Output is correct
72 Correct 19 ms 5456 KB Output is correct
73 Correct 5 ms 2640 KB Output is correct
74 Correct 1 ms 2640 KB Output is correct
75 Correct 126 ms 14408 KB Output is correct
76 Correct 99 ms 14456 KB Output is correct
77 Correct 103 ms 14532 KB Output is correct
78 Correct 110 ms 14408 KB Output is correct
79 Correct 129 ms 14408 KB Output is correct
80 Correct 133 ms 14416 KB Output is correct
81 Correct 78 ms 12624 KB Output is correct
82 Correct 121 ms 12612 KB Output is correct