Submission #36936

# Submission time Handle Problem Language Result Execution time Memory
36936 2017-12-19T09:15:47 Z szawinis Rice Hub (IOI11_ricehub) C++14
100 / 100
23 ms 7092 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 1;

int n, x[N];
ll limit, s[N];

int besthub(int _n, int M, int _x[], ll _limit) {
  n = _n, limit = _limit;
  copy(_x, _x + n, x + 1);
  for(int i = 1; i <= n; i++) s[i] = s[i-1] + x[i];
  int l = 1, r = n;
  while (l < r) {
    int mid = l+r+1 >> 1;
    bool valid = false;
    // cout << mid << ":\n";
    int llen = mid-1 >> 1, rlen = mid >> 1;;
    for(int i = llen + 1; i <= n - rlen; i++) {
       ll resl = 1ll * llen * x[i] - (s[i-1] - s[i - llen - 1]);
       ll resr = s[i + rlen]  - s[i] - 1ll * rlen * x[i];
      //  cout << i << ' ' << resl << ' ' << resr << endl;
       valid |= resl + resr <= limit;
    }
    if (valid) l = mid;
    else r = mid - 1;
  }
  return l;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:16:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l+r+1 >> 1;
                  ^
ricehub.cpp:19:19: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
     int llen = mid-1 >> 1, rlen = mid >> 1;;
                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7092 KB Output is correct
2 Correct 0 ms 7092 KB Output is correct
3 Correct 0 ms 7092 KB Output is correct
4 Correct 0 ms 7092 KB Output is correct
5 Correct 0 ms 7092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7092 KB Output is correct
2 Correct 0 ms 7092 KB Output is correct
3 Correct 0 ms 7092 KB Output is correct
4 Correct 0 ms 7092 KB Output is correct
5 Correct 0 ms 7092 KB Output is correct
6 Correct 0 ms 7092 KB Output is correct
7 Correct 0 ms 7092 KB Output is correct
8 Correct 0 ms 7092 KB Output is correct
9 Correct 0 ms 7092 KB Output is correct
10 Correct 0 ms 7092 KB Output is correct
11 Correct 0 ms 7092 KB Output is correct
12 Correct 0 ms 7092 KB Output is correct
13 Correct 0 ms 7092 KB Output is correct
14 Correct 0 ms 7092 KB Output is correct
15 Correct 0 ms 7092 KB Output is correct
16 Correct 0 ms 7092 KB Output is correct
17 Correct 0 ms 7092 KB Output is correct
18 Correct 0 ms 7092 KB Output is correct
19 Correct 0 ms 7092 KB Output is correct
20 Correct 0 ms 7092 KB Output is correct
21 Correct 0 ms 7092 KB Output is correct
22 Correct 0 ms 7092 KB Output is correct
23 Correct 0 ms 7092 KB Output is correct
24 Correct 0 ms 7092 KB Output is correct
25 Correct 0 ms 7092 KB Output is correct
26 Correct 0 ms 7092 KB Output is correct
27 Correct 0 ms 7092 KB Output is correct
28 Correct 0 ms 7092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7092 KB Output is correct
2 Correct 0 ms 7092 KB Output is correct
3 Correct 0 ms 7092 KB Output is correct
4 Correct 0 ms 7092 KB Output is correct
5 Correct 0 ms 7092 KB Output is correct
6 Correct 0 ms 7092 KB Output is correct
7 Correct 0 ms 7092 KB Output is correct
8 Correct 0 ms 7092 KB Output is correct
9 Correct 0 ms 7092 KB Output is correct
10 Correct 0 ms 7092 KB Output is correct
11 Correct 0 ms 7092 KB Output is correct
12 Correct 0 ms 7092 KB Output is correct
13 Correct 0 ms 7092 KB Output is correct
14 Correct 0 ms 7092 KB Output is correct
15 Correct 0 ms 7092 KB Output is correct
16 Correct 0 ms 7092 KB Output is correct
17 Correct 0 ms 7092 KB Output is correct
18 Correct 0 ms 7092 KB Output is correct
19 Correct 0 ms 7092 KB Output is correct
20 Correct 0 ms 7092 KB Output is correct
21 Correct 0 ms 7092 KB Output is correct
22 Correct 0 ms 7092 KB Output is correct
23 Correct 0 ms 7092 KB Output is correct
24 Correct 0 ms 7092 KB Output is correct
25 Correct 0 ms 7092 KB Output is correct
26 Correct 0 ms 7092 KB Output is correct
27 Correct 0 ms 7092 KB Output is correct
28 Correct 0 ms 7092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7092 KB Output is correct
2 Correct 3 ms 7092 KB Output is correct
3 Correct 19 ms 7092 KB Output is correct
4 Correct 13 ms 7092 KB Output is correct
5 Correct 3 ms 7092 KB Output is correct
6 Correct 16 ms 7092 KB Output is correct
7 Correct 13 ms 7092 KB Output is correct
8 Correct 19 ms 7092 KB Output is correct
9 Correct 9 ms 7092 KB Output is correct
10 Correct 9 ms 7092 KB Output is correct
11 Correct 23 ms 7092 KB Output is correct
12 Correct 19 ms 7092 KB Output is correct
13 Correct 9 ms 7092 KB Output is correct
14 Correct 6 ms 7092 KB Output is correct
15 Correct 19 ms 7092 KB Output is correct
16 Correct 16 ms 7092 KB Output is correct
17 Correct 9 ms 7092 KB Output is correct
18 Correct 16 ms 7092 KB Output is correct
19 Correct 9 ms 7092 KB Output is correct
20 Correct 19 ms 7092 KB Output is correct