Submission #132671

# Submission time Handle Problem Language Result Execution time Memory
132671 2019-07-19T10:11:31 Z letrongdat Pyramid Base (IOI08_pyramid_base) C++17
39 / 100
5000 ms 120412 KB
#include <bits/stdc++.h>
using namespace std;
#define FORN(i, a, b)               for(int i=a; i<=b; ++i)
#define FORD(i, a, b)               for(int i=a; i>=b; --i)
#define REPN(i, a, b)               for(int i=a; i <b; ++i)
#define REPD(i, a, b)               for(int i=(int)a-1; i>=b; --i)
const int maxR = 4*1e5;
const int maxN = 1e6 +10;
const int INF = 1e9 +7;
int M, N, B, P;
typedef tuple<int, int, int> i3;
vector< i3 > open[maxN], close[maxN];
struct Rectangle {
    int x1, y1, x2, y2, cost;
    Rectangle(){};
    Rectangle(int x1, int y1, int x2, int y2): x1(x1), y1(y1), x2(x2), y2(y2) {};
    void expand(int d) {
        open[max(1, x1-d)].push_back({max(1, y1-d), y2, cost});
        close[x2].push_back({max(1, y1-d), y2, cost});
    }
    friend istream & operator >> (istream &is, Rectangle &T) {
        is >> T.x1 >> T.y1 >> T.x2 >> T.y2 >> T.cost;
        return is;
    }
} rec[maxR];
namespace subtask2 {
#define ii      pair<int, int>
    int it[4*maxN], t[4*maxN];
    void lazy(int x, int l, int r) {
        it[x] += t[x];
        if (l != r) {
            t[2*x] += t[x];
            t[2*x+1] += t[x];
        }
        t[x] = 0;
    }
    void update(int x, int l, int r, int i, int j, int cost) {
        lazy(x, l, r);
        if (r < i || j < l) return;
        if (i <= l && r <= j) {
            t[x] = cost;
            lazy(x, l, r);
            return;
        }
        int m = l+r >> 1;
        update(2*x, l, m, i, j, cost);
        update(2*x+1, m+1, r, i, j, cost);
        it[x] = min(it[2*x], it[2*x+1]);
    }
    int query(int x, int l, int r, int i, int j) {
        lazy(x, l, r);
        if (r < i || j < l) return INF;
        if (i <= l && r <= j) return it[x];
        int m = l+r >> 1;
        return min(query(2*x, l, m, i, j), query(2*x+1, m+1, r, i, j));
    }
    bool ok(int d) {
        FORN(i, 1, P) rec[i].expand(d -1);
        open[1].push_back({1, N-d+1, 0});
        open[M-d+1].push_back({1, N-d+1, 0});
        int result = INF;
        FORN(i, 1, M) {
            for(auto ss: open[i]) {
                int y1, y2, cost;
                tie(y1, y2, cost) = ss;
                update(1, 1, N, y1, y2, cost);
                //if (d == 6) cout << "open "<< i << ' ' << y1 << ' ' << y2 <<' ' << cost << '\n';
            }
            if (i <= M-d+1) {
               // if (d == 6) cout << "ans " << i << ' ' << query(1, 1, N, 1, N-d+1) << ' ' << it[1] << '\n';;
                result = min(result, query(1, 1, N, 1, N-d+1));
            }
            for(auto ss: close[i]) {
                int y1, y2, cost;
                tie(y1, y2, cost) = ss;
                update(1, 1, N, y1, y2, -cost);
               // if (d == 6) cout << "close " << i << ' ' << y1 << ' ' << y2 << ' ' << cost << '\n';
            }
        }
        FORN(i, 1, M) open[i].clear(), close[i].clear();
        return (result <= B);
    }
    void run() {
        int low = 0, high = min(M, N), result = 0;
        while (low <= high) {
            int mid = low + high >> 1;
            if (ok(mid)) {
                result = mid;
                low = mid+1;
            } else high = mid-1;
        }
        cout << result;
    }
}
namespace subtask3 {
    void run() {

    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin >> M >> N >> B >> P;
    FORN(i, 1, P) cin >> rec[i];
    if (P <= 3e4) subtask2::run();
        else subtask3::run();
    return 0;
}

Compilation message

pyramid_base.cpp: In function 'void subtask2::update(int, int, int, int, int, int)':
pyramid_base.cpp:45:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
pyramid_base.cpp: In function 'int subtask2::query(int, int, int, int, int)':
pyramid_base.cpp:54:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
pyramid_base.cpp: In function 'void subtask2::run()':
pyramid_base.cpp:86:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int mid = low + high >> 1;
                       ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 47772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 413 ms 49784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1664 ms 58168 KB Output is correct
2 Execution timed out 5048 ms 63916 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 5074 ms 64116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 48120 KB Output is correct
2 Correct 136 ms 48332 KB Output is correct
3 Correct 124 ms 48376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 757 ms 52644 KB Output is correct
2 Correct 950 ms 53224 KB Output is correct
3 Correct 820 ms 53480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3659 ms 69708 KB Output is correct
2 Correct 738 ms 52940 KB Output is correct
3 Correct 381 ms 65528 KB Output is correct
4 Execution timed out 5035 ms 71964 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4734 ms 72608 KB Output is correct
2 Execution timed out 5016 ms 73144 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3523 ms 71068 KB Output is correct
2 Execution timed out 5055 ms 75044 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 156 ms 56924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 61776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 340 ms 120412 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -