답안 #1038558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038558 2024-07-30T00:25:48 Z ArthuroWich 쌀 창고 (IOI11_ricehub) C++17
17 / 100
9 ms 2228 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
int besthub(int n, int L, int x[], long long B) {
    int ans = 0, h = x[0], s = 0, l = 0, r = 1;
    deque<int> left, right;
    for (int i = 1; i < n; i++) {
        if (s+abs(x[i]-x[0]) <= B) {
            s += abs(x[i]-x[0]);
            right.push_back(x[i]);
            r = i;
        }
    }
    ans = right.size()+1;
    for (int i = 1; i < n; i++) {
        int diff = abs(x[i]-h);
        left.push_back(h);
        s += left.size()*diff;
        s -= right.size()*diff;
        if (!right.empty()) {
            right.pop_front();
        }
        h = x[i];
        while(!left.empty() && s > B) {
            s -= abs(left.front()-h);
            left.pop_front();
            l++;
        }
        if (r < i || right.empty()) {
            r = i;
        }
        while(r+1 < n && s+abs(h-x[r+1]) <= B) {
            s += abs(h-x[r+1]);
            right.push_back(x[r+1]);
            r++;
        }
        while(!left.empty() && r+2 < n && s-abs(h-left.front())+abs(h-x[r+1])+abs(h-x[r+2]) <= B) {
            s = s-abs(h-left.front())+abs(h-x[r+1])+abs(h-x[r+2]);
            left.pop_front();
            right.push_back(x[r+1]);
            right.push_back(x[r+2]);
            l++;
            r += 2;
        }
        while(r+1 < n && s+abs(h-x[r+1]) <= B) {
            right.push_back(x[r+1]);
            r++;
        }
        ans = max(ans, (int) left.size() + (int) right.size() + 1);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 448 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 9 ms 2228 KB Output is correct
4 Incorrect 9 ms 2136 KB Output isn't correct
5 Halted 0 ms 0 KB -