# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
18041 |
2016-01-18T17:49:59 Z |
tncks0121 |
매트 (KOI15_mat) |
C++14 |
|
220 ms |
74384 KB |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
const int N_ = 3050;
const int P_ = N_ * 2;
int N, W, X;
struct mat {
int p, l, r, h, k;
mat (int p = 0, int l = 0, int r = 0, int h = 0, int k = 0) : p(p), l(l), r(r), h(h), k(k) { }
};
mat mats[N_];
map<int, int> positions;
vector<int> ends[P_];
int tb[N_][P_];
int rightmost[P_];
int main() {
scanf("%d%d", &N, &W);
for(int i = 1; i <= N; i++) {
mat &m = mats[i];
scanf("%d%d%d%d%d", &m.p, &m.l, &m.r, &m.h, &m.k);
positions[m.l] = -1;
positions[m.r] = -1;
}
{ // 매트들을 오른쪽 좌표 순으로 정렬
sort(mats + 1, mats + N + 1, [&](const mat &a, const mat &b) {
return a.r < b.r;
});
}
{ // renumbering
for(auto &it : positions) it.second = ++X;
for(int i = 1; i <= N; i++) {
mat &m = mats[i];
m.l = positions[m.l];
m.r = positions[m.r];
rightmost[m.r] = i;
ends[m.r].push_back(i);
}
for(int i = 1; i <= X; i++) {
if(rightmost[i] == 0)
rightmost[i] = rightmost[i-1];
}
}
{ // dp
int ans = 0;
for(int i = 1; i <= N; i++) {
mat &m = mats[i];
for(int x = 1; x <= m.l; x++) {
int j = rightmost[x];
int cands[] = {
tb[i][x-1],
//tb[i-1][x],
tb[j][m.r] + m.k
};
tb[i][x] = *max_element(cands, cands + 2);
}
for(int x = m.l + 1; x <= X && x <= m.r; x++) {
tb[i][x] = tb[i][x-1];
for(auto j : ends[x]) {
mat &n = mats[j];
if(n.p == m.p || n.h + m.h > W) continue;
tb[i][x] = max(tb[i][x], max(tb[j][m.l] + m.k, tb[i][n.l] + n.k));
}
}
for(int x = 1; x <= X; x++) {
tb[i][x] = max(tb[i][x], tb[i][x-1]);
}
ans = max(ans, *max_element(tb[i], tb[i] + X + 1));
}
/*
for(int i = 1; i <= N; i++) {
mat &m = mats[i];
printf("%d %d %d %d %d\n", m.p, m.l, m.r, m.h, m.k);
}
puts("");
for(int i = 1; i <= N; i++) {
for(int x = 1; x <= X; x++) {
printf("%4d", tb[i][x]);
}
puts("");
}
*/
printf("%d\n", ans);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
74120 KB |
Output is correct |
2 |
Correct |
0 ms |
74120 KB |
Output is correct |
3 |
Correct |
0 ms |
74120 KB |
Output is correct |
4 |
Incorrect |
0 ms |
74120 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
74120 KB |
Output is correct |
2 |
Correct |
0 ms |
74120 KB |
Output is correct |
3 |
Incorrect |
0 ms |
74120 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
74120 KB |
Output is correct |
2 |
Correct |
0 ms |
74120 KB |
Output is correct |
3 |
Correct |
0 ms |
74120 KB |
Output is correct |
4 |
Incorrect |
0 ms |
74120 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
74384 KB |
Output is correct |
2 |
Correct |
162 ms |
74384 KB |
Output is correct |
3 |
Correct |
180 ms |
74384 KB |
Output is correct |
4 |
Correct |
176 ms |
74384 KB |
Output is correct |
5 |
Incorrect |
3 ms |
74120 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
74384 KB |
Output is correct |
2 |
Correct |
217 ms |
74384 KB |
Output is correct |
3 |
Correct |
220 ms |
74384 KB |
Output is correct |
4 |
Correct |
217 ms |
74384 KB |
Output is correct |
5 |
Correct |
125 ms |
74252 KB |
Output is correct |
6 |
Correct |
169 ms |
74384 KB |
Output is correct |
7 |
Incorrect |
163 ms |
74252 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |