Submission #55850

# Submission time Handle Problem Language Result Execution time Memory
55850 2018-07-09T05:52:12 Z leejseo Rice Hub (IOI11_ricehub) C++
100 / 100
32 ms 1792 KB
#include "ricehub.h"
#include <algorithm>
using namespace std;

long long S[1000001];

inline long long val(int i){
	return i<0? 0 : S[i];
}

inline long long cost(int i, int j, int X[]){
	int mid = i+j >> 1;
	long long left = (long long) X[mid] * (mid - i) - (val(mid-1) - val(i-1));
	long long right = val(j) - val(mid) - (long long) X[mid] * (j - mid);
	return left + right;
}

int besthub(int R, int L, int X[], long long B){
	S[0] = X[0];
	for (int i=1; i<R; i++) S[i] = S[i-1] + X[i];
  int ans = 0;
	int i=0, j=0;
	while (i < R && j < R){
		if (cost(i, j, X) > B){
			i++;
			continue;
		}
		ans = max(ans, j-i+1);
		j++;
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'long long int cost(int, int, int*)':
ricehub.cpp:12:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = i+j >> 1;
            ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 3 ms 564 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 10 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 2 ms 624 KB Output is correct
16 Correct 2 ms 624 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 2 ms 624 KB Output is correct
19 Correct 3 ms 624 KB Output is correct
20 Correct 2 ms 624 KB Output is correct
21 Correct 2 ms 624 KB Output is correct
22 Correct 2 ms 624 KB Output is correct
23 Correct 3 ms 624 KB Output is correct
24 Correct 3 ms 624 KB Output is correct
25 Correct 2 ms 624 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
27 Correct 2 ms 624 KB Output is correct
28 Correct 3 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 624 KB Output is correct
2 Correct 3 ms 624 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 3 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 3 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 3 ms 636 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 3 ms 636 KB Output is correct
24 Correct 3 ms 636 KB Output is correct
25 Correct 3 ms 636 KB Output is correct
26 Correct 3 ms 636 KB Output is correct
27 Correct 3 ms 636 KB Output is correct
28 Correct 3 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 764 KB Output is correct
2 Correct 5 ms 764 KB Output is correct
3 Correct 21 ms 1692 KB Output is correct
4 Correct 25 ms 1788 KB Output is correct
5 Correct 13 ms 1788 KB Output is correct
6 Correct 10 ms 1788 KB Output is correct
7 Correct 19 ms 1792 KB Output is correct
8 Correct 19 ms 1792 KB Output is correct
9 Correct 12 ms 1792 KB Output is correct
10 Correct 11 ms 1792 KB Output is correct
11 Correct 22 ms 1792 KB Output is correct
12 Correct 23 ms 1792 KB Output is correct
13 Correct 10 ms 1792 KB Output is correct
14 Correct 14 ms 1792 KB Output is correct
15 Correct 30 ms 1792 KB Output is correct
16 Correct 19 ms 1792 KB Output is correct
17 Correct 19 ms 1792 KB Output is correct
18 Correct 19 ms 1792 KB Output is correct
19 Correct 32 ms 1792 KB Output is correct
20 Correct 22 ms 1792 KB Output is correct