Submission #857319

# Submission time Handle Problem Language Result Execution time Memory
857319 2023-10-05T21:22:18 Z StefanSebez Self Study (JOI22_ho_t2) C++14
100 / 100
591 ms 11112 KB
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const ull inf=1e18;
int main()
{
    ll n,m;cin>>n>>m;
    ll a[n+1],b[n+1],M=0;
    for(int i=1;i<=n;i++){cin>>a[i];}
    for(int i=1;i<=n;i++){cin>>b[i];}
    ll l=1,r=inf,mid=l+(r-l)/2,res=0;
    while(l<=r)
	{
		//printf("%lld %lld %lld: ",l,mid,r);
		ull sum=0;
		for(ll i=1;i<=n;i++)
		{
			ll x,z,k=inf;
			if(a[i]<=b[i])
			{
				x=0;
				z=(mid+b[i]-1)/b[i];
				k=max(x,z);
			}
			else
			{
				x=mid/a[i];
				if(x>m) x=m;
				z=(mid-x*(a[i]-b[i])+b[i]-1)/b[i];
				k=min(k,max(x,z));
				x++;
				if(x>m) x=m;
				z=(mid-x*(a[i]-b[i])+b[i]-1)/b[i];
				k=min(k,max(x,z));
				//cout<<" {"<<x<<","<<z<<"} ";
			}
			sum+=k;
			ll k1=inf;
			for(ll j=0;j<=m;j++)
			{
				ll z=ceil((double)(mid-j*(a[i]-b[i]))/b[i]);
				k1=min(k1,max(j,z));
			}
			/*int x=0;
			if(a[i]>b[i])x=min(mid/(a[i]-b[i]),m);
			sum+=ceil((mid-x*(a[i]-b[i]))/b[i]);*/
			//cout<<"|"<<k<<" "<<k1<<"| ";
		}
		//cout<<endl;
		if(sum<=n*m)
		{
			res=mid;
			l=mid+1;
		}
		else r=mid-1;
		mid=l+(r-l)/2;
	}
	cout<<res<<endl;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:51:9: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   51 |   if(sum<=n*m)
      |      ~~~^~~~~
Main.cpp:9:22: warning: unused variable 'M' [-Wunused-variable]
    9 |     ll a[n+1],b[n+1],M=0;
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 500 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 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 356 ms 5096 KB Output is correct
12 Correct 359 ms 4956 KB Output is correct
13 Correct 214 ms 4956 KB Output is correct
14 Correct 538 ms 5100 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 217 ms 4956 KB Output is correct
17 Correct 272 ms 4952 KB Output is correct
18 Correct 261 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 217 ms 4956 KB Output is correct
3 Correct 272 ms 4952 KB Output is correct
4 Correct 261 ms 5200 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 0 ms 348 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 129 ms 2756 KB Output is correct
14 Correct 86 ms 1968 KB Output is correct
15 Correct 66 ms 1372 KB Output is correct
16 Correct 52 ms 1116 KB Output is correct
17 Correct 1 ms 348 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 4 ms 504 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 500 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 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 356 ms 5096 KB Output is correct
12 Correct 359 ms 4956 KB Output is correct
13 Correct 214 ms 4956 KB Output is correct
14 Correct 538 ms 5100 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 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 0 ms 348 KB Output is correct
23 Correct 129 ms 2756 KB Output is correct
24 Correct 86 ms 1968 KB Output is correct
25 Correct 66 ms 1372 KB Output is correct
26 Correct 52 ms 1116 KB Output is correct
27 Correct 1 ms 348 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 4 ms 504 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 217 ms 4956 KB Output is correct
36 Correct 272 ms 4952 KB Output is correct
37 Correct 261 ms 5200 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 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 7 ms 348 KB Output is correct
46 Correct 11 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 62 ms 1204 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 6 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 182 ms 2652 KB Output is correct
56 Correct 72 ms 1880 KB Output is correct
57 Correct 179 ms 1880 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 348 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 129 ms 2756 KB Output is correct
10 Correct 86 ms 1968 KB Output is correct
11 Correct 66 ms 1372 KB Output is correct
12 Correct 52 ms 1116 KB Output is correct
13 Correct 1 ms 348 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 4 ms 504 KB Output is correct
19 Correct 5 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 217 ms 4956 KB Output is correct
22 Correct 272 ms 4952 KB Output is correct
23 Correct 261 ms 5200 KB Output is correct
24 Correct 47 ms 1132 KB Output is correct
25 Correct 127 ms 2504 KB Output is correct
26 Correct 28 ms 860 KB Output is correct
27 Correct 258 ms 4952 KB Output is correct
28 Correct 262 ms 5200 KB Output is correct
29 Correct 260 ms 5100 KB Output is correct
30 Correct 269 ms 5200 KB Output is correct
31 Correct 311 ms 4956 KB Output is correct
32 Correct 235 ms 4956 KB Output is correct
33 Correct 341 ms 4956 KB Output is correct
34 Correct 235 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 500 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 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 356 ms 5096 KB Output is correct
12 Correct 359 ms 4956 KB Output is correct
13 Correct 214 ms 4956 KB Output is correct
14 Correct 538 ms 5100 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 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 0 ms 348 KB Output is correct
23 Correct 129 ms 2756 KB Output is correct
24 Correct 86 ms 1968 KB Output is correct
25 Correct 66 ms 1372 KB Output is correct
26 Correct 52 ms 1116 KB Output is correct
27 Correct 1 ms 348 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 4 ms 504 KB Output is correct
33 Correct 5 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 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 7 ms 348 KB Output is correct
42 Correct 11 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 62 ms 1204 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 6 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 182 ms 2652 KB Output is correct
52 Correct 72 ms 1880 KB Output is correct
53 Correct 179 ms 1880 KB Output is correct
54 Correct 47 ms 1132 KB Output is correct
55 Correct 127 ms 2504 KB Output is correct
56 Correct 28 ms 860 KB Output is correct
57 Correct 258 ms 4952 KB Output is correct
58 Correct 262 ms 5200 KB Output is correct
59 Correct 260 ms 5100 KB Output is correct
60 Correct 269 ms 5200 KB Output is correct
61 Correct 311 ms 4956 KB Output is correct
62 Correct 235 ms 4956 KB Output is correct
63 Correct 341 ms 4956 KB Output is correct
64 Correct 235 ms 4956 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 217 ms 4956 KB Output is correct
67 Correct 272 ms 4952 KB Output is correct
68 Correct 261 ms 5200 KB Output is correct
69 Correct 48 ms 1372 KB Output is correct
70 Correct 12 ms 600 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 67 ms 1884 KB Output is correct
73 Correct 15 ms 604 KB Output is correct
74 Correct 2 ms 348 KB Output is correct
75 Correct 364 ms 10724 KB Output is correct
76 Correct 376 ms 11112 KB Output is correct
77 Correct 377 ms 10832 KB Output is correct
78 Correct 412 ms 10860 KB Output is correct
79 Correct 462 ms 10836 KB Output is correct
80 Correct 474 ms 10856 KB Output is correct
81 Correct 279 ms 8920 KB Output is correct
82 Correct 591 ms 8920 KB Output is correct