# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
57324 |
2018-07-14T14:42:13 Z |
leejseo |
매트 (KOI15_mat) |
C++ |
|
343 ms |
73124 KB |
#include <bits/stdc++.h>
using namespace std;
int N, W, ans = 0;
typedef struct cor{
int x, i;
bool r;
cor(int i_, int x_, bool r_){
i = i_, x = x_;
r = r_;
}
bool operator < (const cor &other) const{
if (x != other.x) return x < other.x;
// x == other.x
if (r != other.r) return (!other.r);
return i > other.i;
}
} cor;
typedef struct MAT{
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 &MT) const{
if ((R <= MT.L) || (L >= MT.R)) return false;
if (P == MT.P) return true;
return ((MT.H) + H) > W;
}
bool operator < (const MAT &MT) const{
if (R != MT.R) return R < MT.R;
return L > MT.L;
}
} MAT;
vector<MAT> A;
vector<cor> B;
int D[3001][6001], Left[3001];
bool M[3001][3001];
void input(){
scanf("%d%d", &N, &W);
int P, L, R, H, K;
for (int i=0; i<N; i++){
scanf("%d%d%d%d%d", &P, &L, &R, &H, &K);
A.push_back(MAT(P, L, R, H, K));
}
}
void init(){
sort(A.begin(), A.end());
for (int i=0; i<N; i++){ // sort 한 후, index 값 넣어주기 위해(...)
B.push_back(cor(i, A[i].L, false));
B.push_back(cor(i, A[i].R, true));
}
sort(B.begin(), B.end());
for (int i=0; i<N; i++){
for (int j=0; j<N; j++){
if (A[i].meet(A[j])) M[i][j] = 1; //i and j meet
}
for (int j=0; j<2*N; j++){
if (B[j].i == i){
if (!B[j].r) Left[i] = j;
}
}
}
}
void DP(){
for (int i=0; i<N; i++){
for (int j=0; j<2*N; j++){
if (A[i].R < B[j].x) 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(!M[i][k]){
if (A[k].L < A[i].L){
D[i][j] = max(D[i][j], D[k][Left[i]] + A[i].K);
}
else{
D[i][j] = max(D[i][j], D[i][Left[k]] + A[k].K);
}
}
}
ans = max(ans, D[i][j]);
}
}
}
int main(void){
input();
init();
DP();
printf("%d\n", ans);
}
Compilation message
mat.cpp: In function 'void input()':
mat.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &W);
~~~~~^~~~~~~~~~~~~~~~
mat.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d%d", &P, &L, &R, &H, &K);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
648 KB |
Output is correct |
2 |
Correct |
3 ms |
648 KB |
Output is correct |
3 |
Correct |
0 ms |
648 KB |
Output is correct |
4 |
Correct |
2 ms |
648 KB |
Output is correct |
5 |
Correct |
3 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2164 KB |
Output is correct |
2 |
Correct |
5 ms |
2172 KB |
Output is correct |
3 |
Correct |
5 ms |
2180 KB |
Output is correct |
4 |
Incorrect |
5 ms |
2188 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
66808 KB |
Output is correct |
2 |
Correct |
195 ms |
66828 KB |
Output is correct |
3 |
Correct |
202 ms |
67216 KB |
Output is correct |
4 |
Correct |
197 ms |
67380 KB |
Output is correct |
5 |
Correct |
184 ms |
71484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
214 ms |
73124 KB |
Output is correct |
2 |
Correct |
343 ms |
73124 KB |
Output is correct |
3 |
Correct |
309 ms |
73124 KB |
Output is correct |
4 |
Correct |
319 ms |
73124 KB |
Output is correct |
5 |
Correct |
315 ms |
73124 KB |
Output is correct |
6 |
Correct |
200 ms |
73124 KB |
Output is correct |
7 |
Correct |
307 ms |
73124 KB |
Output is correct |
8 |
Incorrect |
263 ms |
73124 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |