답안 #636578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636578 2022-08-29T15:34:35 Z ghostwriter 쌀 창고 (IOI11_ricehub) C++14
100 / 100
18 ms 2516 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int RMAX = 1e5;
int rs = 0;
ll f[RMAX];
int besthub(int R, int L, int X[], long long B) {
    FOR(i, 0, R - 1) f[i] = (i > 0? f[i - 1] : 0) + X[i];
    FOR(i, 0, R - 1) {
        int l = i, r = R - 1, ans = 0;
        WHILE(l <= r) {
            int mid = l + (r - l) / 2;
            int med = (i + mid) / 2;
            ll mincost = 1LL * (med - i + 1) * X[med] - f[med] + (i > 0? f[i - 1] : 0) + f[mid] - f[med] - 1LL * (mid - med) * X[med];
            if (mincost <= B) {
                ans = mid - i + 1;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        rs = max(rs, ans);
    }
    return rs;
}
/*
5 20 6
1 2 10 12 14
3
*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ricehub.cpp:42:5: note: in expansion of macro 'FOR'
   42 |     FOR(i, 0, R - 1) f[i] = (i > 0? f[i - 1] : 0) + X[i];
      |     ^~~
ricehub.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
ricehub.cpp:43:5: note: in expansion of macro 'FOR'
   43 |     FOR(i, 0, R - 1) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 212 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 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 316 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 320 KB Output is correct
14 Correct 1 ms 212 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 212 KB Output is correct
20 Correct 0 ms 212 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 316 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
# 결과 실행 시간 메모리 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 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 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 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 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 324 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 584 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 18 ms 2468 KB Output is correct
4 Correct 18 ms 2452 KB Output is correct
5 Correct 9 ms 1240 KB Output is correct
6 Correct 9 ms 1204 KB Output is correct
7 Correct 16 ms 2260 KB Output is correct
8 Correct 16 ms 2148 KB Output is correct
9 Correct 8 ms 1108 KB Output is correct
10 Correct 9 ms 1120 KB Output is correct
11 Correct 18 ms 2516 KB Output is correct
12 Correct 18 ms 2504 KB Output is correct
13 Correct 9 ms 1256 KB Output is correct
14 Correct 9 ms 1204 KB Output is correct
15 Correct 14 ms 1976 KB Output is correct
16 Correct 13 ms 1976 KB Output is correct
17 Correct 16 ms 2168 KB Output is correct
18 Correct 16 ms 2192 KB Output is correct
19 Correct 17 ms 2360 KB Output is correct
20 Correct 17 ms 2384 KB Output is correct