답안 #507161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
507161 2022-01-12T09:24:09 Z amukkalir 쌀 창고 (IOI11_ricehub) C++17
100 / 100
17 ms 2492 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll; 

const int nax = 1e5; 
ll p[nax+5]; 

ll cost(int  l, int r) {
  int m = (l+r)>>1; 
  ll d = p[m] - p[m-1]; 
  ll cnt = (r-l)+1; 
  //cout << " :: " << l << " " << r << endl; 
  //cout << (m-l)*d << " - " <<  p[m-1] <<" - " << p[l-1] <<" + " << p[r] << " - " << p[m] <<  " - " << d*(r-m) << " = " << (m-l)*d - p[m-1] + p[l-1] + p[r] - p[m] - d*(r-m) << endl;
  return (m-l)*d - p[m-1] + p[l-1] + p[r] - p[m] - d*(r-m); 
}

int besthub(int R, int L, int X[], long long B)
{ 
  for(int i=1; i<=R; i++) {
    p[i] = X[i-1] + p[i-1]; //make one based
    //cout << i << " " << p[i] << endl; 
  }

  int l = 1, r = 1; 
  int ans = 0; 
  while(l <= R && r <= R) {
    while(r+1 <= R && cost(l, r+1) <= B) {
      r++; 
      //cout << l << " " << r << endl; 
    }
    ans = max(ans, r-l+1); 
    l++; 
  }

  return ans;
}

Compilation message

ricehub.cpp: In function 'll cost(int, int)':
ricehub.cpp:12:6: warning: unused variable 'cnt' [-Wunused-variable]
   12 |   ll cnt = (r-l)+1;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 280 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 300 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 300 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 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 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 17 ms 2440 KB Output is correct
4 Correct 13 ms 2460 KB Output is correct
5 Correct 5 ms 1208 KB Output is correct
6 Correct 5 ms 1228 KB Output is correct
7 Correct 10 ms 2204 KB Output is correct
8 Correct 13 ms 2196 KB Output is correct
9 Correct 4 ms 1184 KB Output is correct
10 Correct 8 ms 1160 KB Output is correct
11 Correct 12 ms 2476 KB Output is correct
12 Correct 12 ms 2492 KB Output is correct
13 Correct 8 ms 1224 KB Output is correct
14 Correct 6 ms 1316 KB Output is correct
15 Correct 9 ms 1964 KB Output is correct
16 Correct 9 ms 1856 KB Output is correct
17 Correct 10 ms 2148 KB Output is correct
18 Correct 11 ms 2252 KB Output is correct
19 Correct 11 ms 2380 KB Output is correct
20 Correct 11 ms 2352 KB Output is correct