답안 #85737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85737 2018-11-21T12:19:21 Z chunghan 매트 (KOI15_mat) C++17
0 / 100
7 ms 1568 KB
#include<bits/stdc++.h>

using namespace std;

int N, W, rst;

class Line {
    public:
        int x, i;
        bool r;
        Line(int x_, int i_, bool r_): x(x), i(i), r(r) {}
        bool operator < (const Line &l) const {
            return x < l.x;
        }
};

class Mat {
    public:
        int P, L, R, H, K;
        Mat(int P, int L, int R, int H, int K): P(P), L(L), R(R), H(H), K(K) {}
        bool meet(const Mat &M) const {
            if (R <= M.L || L >= M.R) return false;
            if (P == M.P) return true;
            return H + M.H > W;
        }
        bool operator < (const Mat &M) const {
            return R != M.R ? R < M.R : L < M.L;
        }
};

vector<Mat> A;
vector<Line> B;
int D[3005][6005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        int P, L, R, H, K;
        cin >> P >> L >> R >> H >> K;
        A.push_back(Mat(P, L, R, H, K));
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        B.push_back(Line(i, A[i].L, false));
        B.push_back(Line(i, A[i].R, true));
    }
    sort(B.begin(), B.end());
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2*N; j++) {
            if (B[j].x > A[i].R) break;
            D[i][j] = A[i].K;
            if (j > 0) D[i][j] = max(D[i][j], D[i][j-1]);
            if (B[j].r) {
                int k = B[j].i;
                if (A[k].R <= A[i].L) {
                    D[i][j] = max(D[i][j], D[k][j] + A[i].K);
                } else if (!A[i].meet(A[k])) {
                    if (A[k].L < A[i].L) {
                        int h = upper_bound(B.begin(), B.end(), Line(-1, A[i].L, 0)) - B.begin() - 1;
                        D[i][j] = max(D[i][j], D[k][h] + A[i].K);
                    } else {
                        int h = upper_bound(B.begin(), B.end(), Line(-1, A[k].L, 0)) - B.begin() - 1;
                        D[i][j] = max(D[i][j], D[i][h] + A[k].K);
                    }
                }
            }
            rst = max(D[i][j], rst);
        }
    }
    cout << rst;
    return 0;
}

Compilation message

mat.cpp: In constructor 'Line::Line(int, int, bool)':
mat.cpp:11:9: warning: 'Line::x' is initialized with itself [-Winit-self]
         Line(int x_, int i_, bool r_): x(x), i(i), r(r) {}
         ^~~~
mat.cpp:11:9: warning: 'Line::i' is initialized with itself [-Winit-self]
mat.cpp:11:9: warning: 'Line::r' is initialized with itself [-Winit-self]
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 584 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 648 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1392 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1568 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -