답안 #741172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741172 2023-05-13T17:40:14 Z shoryu386 쌀 창고 (IOI11_ricehub) C++17
100 / 100
17 ms 5036 KB
#include "ricehub.h"
using namespace std;
#include <bits/stdc++.h>
#define ll long long
ll countPsum[1000007], sumPsum[1000007];
ll countrq(ll a, ll b){
	if (b < a) return 0;
	if (a == 0) return countPsum[b];
	else return countPsum[b] - countPsum[a-1];
}

ll sumrq(ll a, ll b){
	if (b < a) return 0;
	if (a == 0) return sumPsum[b];
	else return sumPsum[b] - sumPsum[a-1];
}


int besthub(int R, int L, int X[], long long B)
{
  vector<pair<ll, ll>> vec;
  for (int x = 0; x < R; x++){
    vec.push_back({X[x], 1});
  }

  ll n = vec.size();
  
  
  countPsum[0] = vec[0].second;
  sumPsum[0] = vec[0].first * vec[0].second;

  for (int x = 1; x < n; x++){
    countPsum[x] = countPsum[x-1] + vec[x].second;

    sumPsum[x] = sumPsum[x-1] + vec[x].first * vec[x].second;
  }
  
  ll l = 0, r = 0; ll ans = 1;
  while (r != n){
	ll median = (l+r)/2;
	ll cost = countrq(l, median-1) * vec[median].first - sumrq(l, median-1)
	  + sumrq(median+1, r) - countrq(median+1, r) * vec[median].first;
	;
	
	if (cost > B) l++;
	else ans = max(r-l+1, ans), r++;
  }
  return ans;
  
  

  
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 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
# 결과 실행 시간 메모리 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 1 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 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 1 ms 212 KB Output is correct
14 Correct 1 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 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 304 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 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 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 612 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 580 KB Output is correct
25 Correct 1 ms 572 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1100 KB Output is correct
2 Correct 4 ms 1100 KB Output is correct
3 Correct 16 ms 3908 KB Output is correct
4 Correct 17 ms 3908 KB Output is correct
5 Correct 7 ms 2120 KB Output is correct
6 Correct 8 ms 2480 KB Output is correct
7 Correct 14 ms 4712 KB Output is correct
8 Correct 14 ms 4656 KB Output is correct
9 Correct 8 ms 2504 KB Output is correct
10 Correct 7 ms 2504 KB Output is correct
11 Correct 17 ms 5036 KB Output is correct
12 Correct 17 ms 4932 KB Output is correct
13 Correct 8 ms 2504 KB Output is correct
14 Correct 8 ms 2496 KB Output is correct
15 Correct 12 ms 3780 KB Output is correct
16 Correct 12 ms 3880 KB Output is correct
17 Correct 14 ms 4504 KB Output is correct
18 Correct 14 ms 4412 KB Output is correct
19 Correct 15 ms 4804 KB Output is correct
20 Correct 15 ms 4804 KB Output is correct