답안 #409574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409574 2021-05-21T05:43:38 Z 600Mihnea 쌀 창고 (IOI11_ricehub) C++17
68 / 100
1000 ms 1320 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

typedef long long ll;

const int N = 100000 + 7;
int n, len, x[N];
ll b;

deque<int> positions;
deque<int> first, second;

ll compute() {
  int x = positions[(int) positions.size() / 2], y;
  if ((int) second.size() == (int) first.size()) {
    y = second.front();
  } else {
   /// cout << (int) first.size() << " and " << (int) second.size() << "\n";
    assert((int) second.size() == (int) first.size() - 1);
    y = first.back();
  }
  assert(x == y);
  ll cost = 0, sum = 0;
  for (auto &p : positions) {
    cost += abs(x - p);
  }
  for (auto &p : first) {
    sum += x - p;
  }
  for (auto &p : second) {
    sum += p - x;
  }
  assert(sum == cost);
  return cost;
}

int besthub(int r, int dim, int rice_fields[], ll gold_coins) {
  n = r;
  len = dim;
  for (int i = 1; i <= n; i++) {
    x[i] = rice_fields[i - 1];
  }
  b = gold_coins;
  int sol = 0;
  for (int i = 1; i <= n; i++) {
    second.push_back(x[i]);
    if ((int) second.size() > (int) first.size()) {
      first.push_back(second.front());
      second.pop_front();
    }
    positions.push_back(x[i]);
    while (compute() > b) {
      positions.pop_front();
      if (first.empty()) {
        second.pop_front();
      } else {
        first.pop_front();
      }
      if ((int) second.size() > (int) first.size()) {
        first.push_back(second.front());
        second.pop_front();
      }
    }
    sol = max(sol, (int) positions.size());
  }
  return sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 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 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 6 ms 460 KB Output is correct
22 Correct 6 ms 332 KB Output is correct
23 Correct 27 ms 384 KB Output is correct
24 Correct 27 ms 368 KB Output is correct
25 Correct 28 ms 380 KB Output is correct
26 Correct 27 ms 376 KB Output is correct
27 Correct 29 ms 332 KB Output is correct
28 Correct 29 ms 368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 460 KB Output is correct
2 Correct 12 ms 468 KB Output is correct
3 Execution timed out 1097 ms 1320 KB Time limit exceeded
4 Halted 0 ms 0 KB -