제출 #530809

#제출 시각아이디문제언어결과실행 시간메모리
530809SlavicG쌀 창고 (IOI11_ricehub)C++17
100 / 100
16 ms2960 KiB
#include "bits/stdc++.h" #include "ricehub.h" using namespace std; #define ll long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() ll query(int l, int r, vector<ll>& p) { return p[r] - (l ? p[l - 1] : 0); } bool ok(int val, vector<int>& x, ll b) { int n = sz(x); vector<ll> p(n); for(int i = 0;i < n; ++i) { p[i] = (i ? p[i - 1] : 0) + x[i]; } for(int i = 0; i + val - 1 < n; ++i) { ll med = (i + val / 2); ll calc = 1LL * x[med] * (i + val / 2 - i + 1) - query(i, i + val / 2, p); if(calc > b) continue; calc += 1LL * query(i + val / 2, i + val - 1, p) - 1LL * x[med] * (i + val - 1 - i - val / 2 + 1); if(calc <= b) return true; } return false; } int besthub(int R, int L, int f[], ll b) { int l = 1, r = R, ans = 0; vector<int> x; for(int i = 0;i < R; ++i) x.pb(f[i]); while(l <= r) { int mid = l + r >> 1; if(ok(mid, x, b)) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; } /* void solve() { int r, l; ll b; cin >> r >> l >> b; vector<int> x(r); forn(i, r) cin >> x[i]; cout << besthub(r, l, x, b) << "\n"; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t = 1; //cin >> t; while(t--) { solve(); } } */

컴파일 시 표준 에러 (stderr) 메시지

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:41:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |         int mid = l + r >> 1;
      |                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...