Submission #891743

# Submission time Handle Problem Language Result Execution time Memory
891743 2023-12-23T21:38:24 Z Macker Pyramid Base (IOI08_pyramid_base) C++17
80 / 100
5000 ms 143224 KB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

int st[2097157];
int lz[2097157];
int len = 1;

void init(int n){
    len = 1;
    while(len < n) len *= 2;
    for (int i = len; i < len + n; i++) {
        st[i] = 0;
        lz[i] = 0;
    }
    for (int i = len + n; i < 2 * len; i++){
        st[i] = INT_MAX;
        lz[i] = 0;
    }
    for (int i = len - 1; i > 0; i--) {
        st[i] = min(st[i * 2], st[i * 2 + 1]);
        lz[i] = 0;
    }
}

void prop(int i){
    st[i * 2] += lz[i];
    st[i * 2 + 1] += lz[i];
    lz[i * 2] += lz[i];
    lz[i * 2 + 1] += lz[i];
    lz[i] = 0;
}

void add(int f, int t, int v, int i = 1, int s = 0, int e = len){
    if(f >= e || s >= t) return;
    if(f <= s && e <= t){
        st[i] += v;
        lz[i] += v;
        return;
    }
    prop(i);
    add(f, t, v, i * 2, s, (s + e) / 2);
    add(f, t, v, i * 2 + 1, (s + e) / 2, e);
    st[i] = min(st[i * 2], st[i * 2 + 1]);
}

vector<tuple<int, int, int, int>> ev[1000005]; //[y][i] -> t(0s, 1e), x, xx, c
bool can(int d, vector<array<int, 5>> v, int w, int h, int b){
    w -= d;
    h -= d;
    for (auto &i : v) {
        i[0] = max(0, i[0] - d);
        i[1] = max(0, i[1] - d);
        i[2] = min(w - 1, i[2]);
        i[3] = min(h - 1, i[3]);
    }

    init(w);
    for (int i = 0; i < 1000005; i++) {
        ev[i] = {};
    }
    for (auto& i : v) {
        ev[i[1]].push_back({0, i[0], i[2], i[4]});
        ev[i[3] + 1].push_back({1, i[0], i[2], i[4]});
    }
    int y = 0;
    for (auto& es : ev) {
        for (auto& e : es) {
            auto& [t, x, xx, c] = e;
            if(t == 0){
                add(x, xx + 1, c);
            }
            else{
                add(x, xx + 1, -c);
            }
        }
        
        if(y >= h) break;
        if(st[1] <= b) return true;
        y++;
    }
    
    return false;
}
 
int main()
{
    int w, h; cin >> w >> h;
    int b; cin >> b;
    int n; cin >> n;
    vector<array<int, 5>> v(n);
    for (auto &i : v){
        cin >> i[0] >> i[1] >> i[2] >> i[3] >> i[4];
        for (int j = 0; j < 4; j++)
            i[j]--;
    }
 
 
    int l = -1, r = min(w, h), mid;
    while(l < r){
        mid = (l + r + 1) / 2;
        if(can(mid, v, w, h, b)) l = mid;
        else r = mid - 1;
    }
    
    cout << l + 1 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 27480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 27484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 27728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 35776 KB Output is correct
2 Correct 189 ms 40900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 41000 KB Output is correct
2 Correct 103 ms 35864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 28860 KB Output is correct
2 Correct 59 ms 28252 KB Output is correct
3 Correct 68 ms 28260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 32048 KB Output is correct
2 Correct 255 ms 31916 KB Output is correct
3 Correct 251 ms 32284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 284 ms 45440 KB Output is correct
2 Correct 140 ms 44992 KB Output is correct
3 Correct 70 ms 33104 KB Output is correct
4 Correct 617 ms 51672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 498 ms 53216 KB Output is correct
2 Correct 834 ms 53712 KB Output is correct
3 Correct 287 ms 46600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 435 ms 49900 KB Output is correct
2 Correct 1000 ms 56560 KB Output is correct
3 Correct 928 ms 56772 KB Output is correct
4 Correct 998 ms 56832 KB Output is correct
5 Correct 940 ms 56484 KB Output is correct
6 Correct 237 ms 48668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4252 ms 93684 KB Output is correct
2 Correct 1875 ms 143224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5059 ms 109480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5064 ms 117660 KB Time limit exceeded
2 Halted 0 ms 0 KB -