답안 #93996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93996 2019-01-14T13:06:45 Z fjzzq2002 쌀 창고 (IOI11_ricehub) C++14
100 / 100
222 ms 2664 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qz[123456];
int besthub(int N,int L_,int X[],ll B)
{
	int ans=0;
	for(int i=0;i<N;++i)
		qz[i+1]=qz[i]+X[i];
	for(int i=0;i<N;++i)
	{
		int u=X[i];
		int L=0,R=1.01e9;
		while(L<R)
		{
			int M=(L+R+1)>>1;
			int u1=lower_bound(X,X+N,u-M)-X,
			u2=lower_bound(X,X+N,u+M+1)-X-1;
			//[u1,i] [i,u2]
			ll co=(i-u1+1)*ll(u)-(qz[i+1]-qz[u1])
			+(qz[u2+1]-qz[i])-(u2-i+1)*ll(u);
			int cn=u2-u1+1;
			if(co>B) R=M-1; else L=M;
		}
		{
			int M=L;
			int u1=lower_bound(X,X+N,u-M)-X,
			u2=lower_bound(X,X+N,u+M+1)-X-1;
			//[u1,i] [i,u2]
			ll co=(i-u1+1)*ll(u)-(qz[i+1]-qz[u1])
			+(qz[u2+1]-qz[i])-(u2-i+1)*ll(u);
			int cn=u2-u1+1;
			ll w=B-co;
			if(cn!=N) cn+=w/(M+1);
			ans=max(ans,cn);
		}
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:23:8: warning: unused variable 'cn' [-Wunused-variable]
    int cn=u2-u1+1;
        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 420 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 380 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 8 ms 376 KB Output is correct
22 Correct 8 ms 376 KB Output is correct
23 Correct 7 ms 504 KB Output is correct
24 Correct 9 ms 376 KB Output is correct
25 Correct 9 ms 504 KB Output is correct
26 Correct 11 ms 376 KB Output is correct
27 Correct 11 ms 504 KB Output is correct
28 Correct 11 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 632 KB Output is correct
2 Correct 49 ms 632 KB Output is correct
3 Correct 149 ms 2552 KB Output is correct
4 Correct 222 ms 2664 KB Output is correct
5 Correct 76 ms 1272 KB Output is correct
6 Correct 76 ms 1276 KB Output is correct
7 Correct 138 ms 2372 KB Output is correct
8 Correct 153 ms 2300 KB Output is correct
9 Correct 85 ms 1144 KB Output is correct
10 Correct 86 ms 1272 KB Output is correct
11 Correct 157 ms 2656 KB Output is correct
12 Correct 206 ms 2552 KB Output is correct
13 Correct 120 ms 1272 KB Output is correct
14 Correct 121 ms 1280 KB Output is correct
15 Correct 111 ms 2080 KB Output is correct
16 Correct 151 ms 2040 KB Output is correct
17 Correct 130 ms 2300 KB Output is correct
18 Correct 180 ms 2296 KB Output is correct
19 Correct 138 ms 2424 KB Output is correct
20 Correct 198 ms 2552 KB Output is correct