Submission #563337

# Submission time Handle Problem Language Result Execution time Memory
563337 2022-05-17T00:19:13 Z 1ne Rice Hub (IOI11_ricehub) C++14
100 / 100
15 ms 4908 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
  int ans = 0;
  vector<int64_t>pref(R + 1,0),dpref(R + 1,0);
  vector<int64_t>suff(R + 1,0),dsuff(R + 1,0);
  for (int i = 0 ;i<R - 1;++i){
	  pref[i + 1] = pref[i] + (X[i + 1] - X[i]);
	  dpref[i + 2] = pref[i + 1] + dpref[i + 1];
  }
   for (int i = R - 2 ;i>=0;--i){
	  suff[i] = suff[i + 1] + (X[i + 1] - X[i]);
	  dsuff[i] = suff[i] + dsuff[i + 1];
  }
 auto dist = [&](int l,int r){
	 return pref[r] * (r - l) - dpref[r] + dpref[l];
  };
  auto dist2 = [&](int l,int r){
	 return suff[l] * (r - l) + dsuff[r + 1] - dsuff[l + 1];
  };
  auto distt = [&](int l,int r){
		int mid = (l + r)>>1;
		return dist(l,mid) + dist2(mid,r);
	};
    int l = 0,r = 0;
  while(l<=r && r < R){
	  if (r + 1 < R && distt(l,r + 1)<=B){
		  ++r;
	  } 
	  else if (l + 1<=r) {
		  ++l;
	  }
	  else {
		l++;
		r = l;
	  }
	  //cout<<r<<" "<<l<<" "<<distt(l,r)<<'\n';
	  ans = max(ans,r - l + 1);
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 224 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 980 KB Output is correct
2 Correct 3 ms 980 KB Output is correct
3 Correct 14 ms 3772 KB Output is correct
4 Correct 15 ms 3744 KB Output is correct
5 Correct 7 ms 2004 KB Output is correct
6 Correct 6 ms 2388 KB Output is correct
7 Correct 13 ms 4564 KB Output is correct
8 Correct 13 ms 4564 KB Output is correct
9 Correct 6 ms 2260 KB Output is correct
10 Correct 6 ms 2372 KB Output is correct
11 Correct 14 ms 4908 KB Output is correct
12 Correct 15 ms 4896 KB Output is correct
13 Correct 6 ms 2372 KB Output is correct
14 Correct 7 ms 2388 KB Output is correct
15 Correct 10 ms 3668 KB Output is correct
16 Correct 12 ms 3624 KB Output is correct
17 Correct 14 ms 4308 KB Output is correct
18 Correct 14 ms 4296 KB Output is correct
19 Correct 14 ms 4564 KB Output is correct
20 Correct 13 ms 4572 KB Output is correct