Submission #104099

# Submission time Handle Problem Language Result Execution time Memory
104099 2019-04-04T03:07:40 Z wilwxk Rice Hub (IOI11_ricehub) C++11
100 / 100
26 ms 2964 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN=1e5+3;
int v[MAXN];
ll ps[MAXN];
int n, m;
int ini, fim;
ll x;

ll soma(int ini, int fim) { if(fim<ini) return 0; return ps[fim]- (ini==0 ? 0 : ps[ini-1]); }

bool testa(int k) {
	for(int fim=k-1; fim<n; fim++) {
		int ini=fim-k+1;
		int mid=(ini+fim)/2;
		ll aa=v[mid]; aa*=(mid-ini+1); aa-=soma(ini, mid);
		ll bb=soma(mid+1, fim); if(mid<fim) bb-=v[mid]*(ll)(fim-mid);
		// printf("test %d %d [%d] > m %d > %lld %lld > %lld\n", ini, fim, k, mid, aa, bb, aa+bb);
		if(aa+bb<=x) return 1;
	}
	return 0;
}

int besthub(int N, int M, int V[], ll X)
{

	n=N; m=M; x=X;
	for(int i=0; i<n; i++) v[i]=V[i];
	ps[0]=v[0]; for(int i=1; i<n; i++) ps[i]=ps[i-1]+v[i];

	int tam=0;
	for(int i=n; i>0; i/=2) while(tam+i<=n&&testa(tam+i)) tam+=i;

	return tam;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 300 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 316 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 4 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
3 Correct 26 ms 2964 KB Output is correct
4 Correct 20 ms 2936 KB Output is correct
5 Correct 15 ms 1408 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 20 ms 2680 KB Output is correct
8 Correct 15 ms 2688 KB Output is correct
9 Correct 12 ms 1408 KB Output is correct
10 Correct 14 ms 1408 KB Output is correct
11 Correct 20 ms 2936 KB Output is correct
12 Correct 18 ms 2936 KB Output is correct
13 Correct 13 ms 1536 KB Output is correct
14 Correct 11 ms 1536 KB Output is correct
15 Correct 21 ms 2304 KB Output is correct
16 Correct 16 ms 2304 KB Output is correct
17 Correct 18 ms 2688 KB Output is correct
18 Correct 19 ms 2680 KB Output is correct
19 Correct 21 ms 2808 KB Output is correct
20 Correct 22 ms 2816 KB Output is correct