답안 #220057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
220057 2020-04-06T21:33:24 Z tatyam Pyramid Base (IOI08_pyramid_base) C++17
80 / 100
5000 ms 45164 KB
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
const int INF = 0x3fffffff;
template<class T, class U> bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
#define rep(b) for(ll i = 0; i < b; i++)
#define each(i,a) for(auto&& i : a)
#define all(a) begin(a), end(a)

struct SegTree{
    int n;
    vector<ll> data, lazy;
    SegTree(int n): n(n), data(n * 2), lazy(n * 2){}
    inline ll get() const {
        return data[1];
    }
    inline void add(int l, int r, int val){
        if(l < 0) l = 0;
        if(r > n) r = n;
        l += n;
        r += n;
        int L = l, R = r;
        for(; L < R; L /= 2, R /= 2){
            if(L & 1){
                data[L] += val;
                lazy[L++] += val;
            }
            if(R & 1){
                data[--R] += val;
                lazy[R] += val;
            }
        }
        r--;
        while(l /= 2) data[l] = min(data[l * 2], data[l * 2 | 1]) + lazy[l];
        while(r /= 2) data[r] = min(data[r * 2], data[r * 2 | 1]) + lazy[r];
    }
};
int main(){
    int m, n, b, p;
    scanf("%u %u %u %u", &m, &n, &b, &p);
    using tuplis = array<int, 4>;
    vector<tuplis> in, out;
    rep(p){
        int x1, y1, x2, y2, c;
        scanf("%u %u %u %u %u", &x1, &y1, &x2, &y2, &c);
        x1--; y1--;
        in.push_back({x1, y1, y2, c});
        out.push_back({x2, y1, y2, -c});
    }
    sort(all(in));
    sort(all(out));
    in.push_back({INF, 0, 0, 0});
    out.push_back({INF, 0, 0, 0});
    auto check = [&](int x) -> bool {
        x--;
        SegTree seg(n - x);
        int i1 = 0, i2 = 0, at = 0;
        while(at < m - x){
            while(in[i1][0] <= at + x){
                seg.add(in[i1][1] - x, in[i1][2], in[i1][3]);
                i1++;
            }
            while(out[i2][0] <= at){
                seg.add(out[i2][1] - x, out[i2][2], out[i2][3]);
                i2++;
            }
            if(seg.get() <= b) return 1;
            at = min(in[i1][0] - x, out[i2][0]);
        }
        return 0;
    };
    int ok = 0, ng = min(n, m) + 1;
    while(ng - ok > 1){
        ll cen = (ok + ng) / 2;
        if(check(cen)) ok = cen;
        else ng = cen;
    }
    cout << ok << endl;
}

Compilation message

pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%u %u %u %u", &m, &n, &b, &p);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%u %u %u %u %u", &x1, &y1, &x2, &y2, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 3344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16128 KB Output is correct
2 Correct 305 ms 31864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 29864 KB Output is correct
2 Correct 41 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 768 KB Output is correct
2 Correct 38 ms 1128 KB Output is correct
3 Correct 36 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 3796 KB Output is correct
2 Correct 191 ms 4516 KB Output is correct
3 Correct 183 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 17384 KB Output is correct
2 Correct 25 ms 1788 KB Output is correct
3 Correct 236 ms 32884 KB Output is correct
4 Correct 368 ms 31156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 25564 KB Output is correct
2 Correct 833 ms 33428 KB Output is correct
3 Correct 155 ms 17780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 291 ms 18020 KB Output is correct
2 Correct 1027 ms 33824 KB Output is correct
3 Correct 982 ms 34056 KB Output is correct
4 Correct 1048 ms 33764 KB Output is correct
5 Correct 1043 ms 33912 KB Output is correct
6 Correct 128 ms 18028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4266 ms 39272 KB Output is correct
2 Correct 343 ms 9920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5058 ms 42120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5056 ms 45164 KB Time limit exceeded
2 Halted 0 ms 0 KB -