Submission #615573

# Submission time Handle Problem Language Result Execution time Memory
615573 2022-07-31T10:44:21 Z Apiram Rice Hub (IOI11_ricehub) C++14
100 / 100
28 ms 4888 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 312 KB Output is correct
3 Correct 5 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 312 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 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 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 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 8 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 476 KB Output is correct
28 Correct 2 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 17 ms 4888 KB Output is correct
4 Correct 19 ms 4820 KB Output is correct
5 Correct 8 ms 2372 KB Output is correct
6 Correct 19 ms 2388 KB Output is correct
7 Correct 13 ms 4564 KB Output is correct
8 Correct 13 ms 4552 KB Output is correct
9 Correct 6 ms 2332 KB Output is correct
10 Correct 6 ms 2372 KB Output is correct
11 Correct 28 ms 4812 KB Output is correct
12 Correct 15 ms 4808 KB Output is correct
13 Correct 11 ms 2416 KB Output is correct
14 Correct 7 ms 2372 KB Output is correct
15 Correct 11 ms 3668 KB Output is correct
16 Correct 13 ms 3660 KB Output is correct
17 Correct 15 ms 4288 KB Output is correct
18 Correct 13 ms 4364 KB Output is correct
19 Correct 18 ms 4564 KB Output is correct
20 Correct 17 ms 4564 KB Output is correct