답안 #739953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739953 2023-05-11T18:26:20 Z swagchicken 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
 
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
#define endl '\n';
#define sz(x) (int)(x).size()
 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
 

int r; 
vector<ll> x;
vector<ll> pre;
ll l;
ll b;

bool test(int k) {
    FOR(i,0,r-k+1) {
        int mid = (i + i + k - 1)/2;
        
        ll lft = mid - i + 1;
        ll rgt = (i + k - 1) - mid;

       // cout << lft << " " << rgt << endl;

        ll tot = lft * x[mid] - (pre[mid+1] - pre[i]) + (pre[i + k] - pre[mid + 1]) - rgt * x[mid];
        if(tot <= b) {
            cout << i << " " << i + k-1 <<endl;
            return true;
        }
    }
    return false;
}

int besthub(ll R, ll L, ll X[], ll B) {
    r = R
    FOR(i,0,r) x.pb(X[i]);
    l = L;
    b = B;

    pre.resize(r+1);
    FOR(i,1,r+1) {
        pre[i] = x[i-1] + pre[i-1];
    }

    int lo = 1;
    int hi = r;
    while(lo != hi) {
        int mid = (lo + hi + 1)/2;

        bool good = test(mid);
        if(good) {
            lo = mid;
        } else {
            hi = mid-1;
        }
    }
    return lo;
}


Compilation message

ricehub.cpp: In function 'int besthub(ll, ll, ll*, ll)':
ricehub.cpp:54:10: error: expected ';' before 'for'
   54 |     r = R
      |          ^
      |          ;
ricehub.cpp:55:9: error: 'i' was not declared in this scope
   55 |     FOR(i,0,r) x.pb(X[i]);
      |         ^
ricehub.cpp:17:35: note: in definition of macro 'FOR'
   17 | #define FOR(i,a,b) for(int i = a; i < b; i ++)
      |                                   ^