답안 #207539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207539 2020-03-07T20:19:58 Z robs 쌀 창고 (IOI11_ricehub) C++17
100 / 100
25 ms 2296 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define debug(args...) //fprintf(stderr, args)
typedef long long int lli;
using namespace std;
const lli maxn = 2e5;
lli s[maxn],cs[maxn],I,J,SUM;

int besthub(int R, int L, int X[], long long int B)
{
	s[0] = X[0];
	// debug("R-1 = %d\n",R-1);
	for(int x = 1; x < R; x++)
		s[x] = s[x-1] + X[x];
	for(int x = 0; x < R; x++)
		// debug("s[%d] = %d | d = %d\n",x,s[x],X[x]);
	cs[R-1] = 0;
	// debug("\n");
	for(int x = R-2; x >= 0; x--)
		cs[x] = cs[x+1] + X[R-1] - X[x];
	// for(int x = 0; x < R; x++)
		// debug("cs[%d] = %d | d = %d\n",x,cs[x],X[R-1]-X[x]);
	// debug("\n\n");
	lli i = 0;
	lli j = 0;
	lli resp = 0;
	while(j < R)
	{
		lli med = (i + j) / 2;
		lli sumEsq = (cs[i] - cs[med]) - ((med - i)*(X[R-1] - X[med]));
		// debug("%d - %d:\nsumEsq = %d = (%d-%d) - ((%d-%d)*(%d-%d))\n",i,j,sumEsq,cs[i],cs[med],med,i,X[R-1],X[med]);
		lli sumDir = (s[j] - s[med]) - ((j - med)*X[med]);
		// debug("sumDir = %d = (%d-%d) - ((%d-%d)*(%d-%d))\n",sumDir,s[j],s[med],j,med,X[med],X[0]);
		lli sum = sumEsq + sumDir;
		lli r = j - i + 1;
		// debug("%d - %d(%d)	%d  %d 		-%d-\n\n",i,j,sum,sumEsq,sumDir,med);
		if(sum <= B)
		{
			resp = max(resp, r);
			j++;
		}
		else if(i == j)
		{
			j++;
		}
		else	i++;
	}
	return resp;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 280 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 348 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 380 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 5 ms 508 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 760 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 21 ms 2296 KB Output is correct
4 Correct 22 ms 2296 KB Output is correct
5 Correct 12 ms 1272 KB Output is correct
6 Correct 13 ms 1272 KB Output is correct
7 Correct 19 ms 2296 KB Output is correct
8 Correct 19 ms 2296 KB Output is correct
9 Correct 11 ms 1276 KB Output is correct
10 Correct 13 ms 1400 KB Output is correct
11 Correct 25 ms 2168 KB Output is correct
12 Correct 24 ms 2296 KB Output is correct
13 Correct 12 ms 1272 KB Output is correct
14 Correct 13 ms 1272 KB Output is correct
15 Correct 19 ms 1784 KB Output is correct
16 Correct 18 ms 1784 KB Output is correct
17 Correct 22 ms 2016 KB Output is correct
18 Correct 22 ms 2168 KB Output is correct
19 Correct 24 ms 2168 KB Output is correct
20 Correct 21 ms 2168 KB Output is correct