답안 #499573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499573 2021-12-28T19:00:48 Z aryan12 쌀 창고 (IOI11_ricehub) C++17
100 / 100
13 ms 2504 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int rice, int len, int a[], long long b) {
    long long pref[rice], suf[rice];
    pref[0] = a[0];
    for(long long i = 1; i < rice; i++) {
      pref[i] = pref[i - 1] + a[i];
    }
    long long right = 0, ans = 0;
    for(long long left = 0; left < rice; left++) {
      right = max(right, left);
      while(right != rice) {
        long long mid = (left + right) / 2;
        long long cur_ans;
        if(left != 0) cur_ans = a[mid] * (mid - left + 1) - pref[mid] + pref[left - 1];
        else cur_ans = a[mid] * (mid - left + 1) - pref[mid];
        if(mid != 0) cur_ans += pref[right] - pref[mid - 1] - a[mid] * (right - mid + 1);
        else cur_ans += pref[right] - a[mid] * (right - mid + 1);
        //cout << "l = " << left << ", mid = " << mid << ", right = " << right << ", cur_ans = " << cur_ans << "\n";
        if(cur_ans <= b) {
          ans = max(ans, right - left + 1);
        }
        else {
          break;
        }
        right++;
      }
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:6:27: warning: unused variable 'suf' [-Wunused-variable]
    6 |     long long pref[rice], suf[rice];
      |                           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 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 1 ms 204 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 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 300 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 304 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 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 0 ms 308 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 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 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 2 ms 324 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 12 ms 2504 KB Output is correct
4 Correct 11 ms 2484 KB Output is correct
5 Correct 7 ms 1092 KB Output is correct
6 Correct 5 ms 1184 KB Output is correct
7 Correct 10 ms 2232 KB Output is correct
8 Correct 11 ms 2208 KB Output is correct
9 Correct 5 ms 1184 KB Output is correct
10 Correct 5 ms 1080 KB Output is correct
11 Correct 11 ms 2488 KB Output is correct
12 Correct 12 ms 2460 KB Output is correct
13 Correct 6 ms 1196 KB Output is correct
14 Correct 6 ms 1228 KB Output is correct
15 Correct 9 ms 1876 KB Output is correct
16 Correct 9 ms 1944 KB Output is correct
17 Correct 10 ms 2244 KB Output is correct
18 Correct 11 ms 2240 KB Output is correct
19 Correct 13 ms 2380 KB Output is correct
20 Correct 11 ms 2384 KB Output is correct