답안 #827051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827051 2023-08-16T08:23:32 Z wortelworm 쌀 창고 (IOI11_ricehub) C++17
17 / 100
17 ms 1772 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int besthub(int RiceCount, int Length, int RiceFields[], long long Budget)
{
    int count_before = 0;
    int count_after = 0;
    ll cost = 0;

    int best_count = 1;

    for (int i = 1; i < RiceCount; i++)
    {
        // set the hub at this field
        int x = RiceFields[i];
        ll distance = RiceFields[i] - RiceFields[i-1];

        // account for the prev_index now also having distance
        count_before++;

        cost += distance * count_before;
        cost -= distance * count_after;

        if (count_after > 0) {
            count_after --;
        }

        while (cost > Budget) {
            cost -= x - RiceFields[i-count_before];
            count_before--;

            if (count_before < 0) {
                cerr << "???\n\n";
                return -1;
            }
        }

        while (cost <= Budget && i+count_after < RiceCount-1) {
            count_after++;
            cost += RiceFields[i+count_after] - x;
        }

        if (cost > Budget) {
            cost -= RiceFields[i+count_after] - x;
            count_after--;
        }

        int current_count = count_before + count_after + 1;
        if (current_count > best_count) {
            best_count = current_count;
        }
    }

    return best_count;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 308 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 0 ms 312 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 9 ms 1772 KB Output is correct
4 Correct 9 ms 1716 KB Output is correct
5 Correct 4 ms 828 KB Output is correct
6 Correct 4 ms 832 KB Output is correct
7 Correct 8 ms 1456 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 13 ms 1772 KB Output is correct
12 Correct 17 ms 1720 KB Output is correct
13 Incorrect 5 ms 864 KB Output isn't correct
14 Halted 0 ms 0 KB -