답안 #71307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
71307 2018-08-24T10:32:22 Z octopuses 매트 (KOI15_mat) C++17
100 / 100
54 ms 30788 KB
//Giorgi Kldiashvili

#include <bits/stdc++.h>

#define ll long long

using namespace std;
const int N = 3020;

struct node
{
  int l, r, h, c;
};

bool operator < (node a, node b)
{
  if(a.r == b.r)
    return a.l < b.l;
  return a.r < b.r;
}

int tot, H, n, m;

bool check(node a, node b)
{
  if(a.r <= b.l || b.r <= a.l)
    return false;
  if(a.h + b.h > H)
    return true;
  return false;
}

vector < node > a, b;
int A[N], B[N];
int C[N][N], D[N][N];
int answer;

int main()
{
  scanf("%d %d", &tot, &H);
  a.push_back({0, 0, 0, 0});
  b.push_back({0, 0, 0, 0});
  while(tot --)
  {
    int id, l, r, h, cost;
    scanf("%d %d %d %d %d", &id, &l, &r, &h, &cost);
    if(id == 0)
      a.push_back({l, r, h, cost});
    else
      b.push_back({l, r, h, cost});
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  n = a.size() - 1; m = b.size() - 1;
  for(int i = 1; i <= n; ++ i)
  {
    int l = 0; int r = i - 1;
    while(l < r)
    {
      int mid = l + r + 1 >> 1;
      if(a[mid].r <= a[i].l)
        l = mid;
      else
        r = mid - 1;
    }
    A[i] = l;
  }
  for(int i = 1; i <= m; ++ i)
  {
    int l = 0; int r = i - 1;
    while(l < r)
    {
      int mid = l + r + 1 >> 1;
      if(b[mid].r <= b[i].l)
        l = mid;
      else
        r = mid - 1;
    }
    B[i] = l;
  }
  for(int i = 1; i <= m; ++ i)
  {
    D[0][i] = C[0][B[i]] + b[i].c;
    C[0][i] = max(C[0][i - 1], D[0][i]);
  }
  for(int i = 1; i <= n; ++ i)
  {
    C[i][0] = D[A[i]][0] + a[i].c;
    D[i][0] = max(D[i - 1][0], C[i][0]);
    for(int j = 1; j <= m; ++ j)
    {
      C[i][j] = C[i][j - 1];
      D[i][j] = D[i - 1][j];
      if(check(a[i], b[j]))
        continue;
      int now = 0;
      if(a[i].l < b[j].l)
        now = C[i][B[j]] + b[j].c;
      else
        now = D[A[i]][j] + a[i].c;
      C[i][j] = max(C[i][j], now);
      D[i][j] = max(D[i][j], now);
    }
  }
  for(int i = 0; i <= n; ++ i)
    for(int j = 0; j <= m; ++ j)
    {
      answer = max(answer, C[i][j]);
      answer = max(answer, D[i][j]);
    }
  printf("%d\n", answer);
}

Compilation message

mat.cpp: In function 'int main()':
mat.cpp:60:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
       int mid = l + r + 1 >> 1;
                 ~~~~~~^~~
mat.cpp:73:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
       int mid = l + r + 1 >> 1;
                 ~~~~~~^~~
mat.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &tot, &H);
   ~~~~~^~~~~~~~~~~~~~~~~~~
mat.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d %d", &id, &l, &r, &h, &cost);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 4 ms 620 KB Output is correct
5 Correct 3 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 2 ms 664 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 3 ms 664 KB Output is correct
5 Correct 3 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1488 KB Output is correct
2 Correct 3 ms 1488 KB Output is correct
3 Correct 3 ms 1488 KB Output is correct
4 Correct 3 ms 1488 KB Output is correct
5 Correct 4 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 24784 KB Output is correct
2 Correct 23 ms 24908 KB Output is correct
3 Correct 29 ms 25012 KB Output is correct
4 Correct 24 ms 25112 KB Output is correct
5 Correct 30 ms 25212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 30276 KB Output is correct
2 Correct 54 ms 30660 KB Output is correct
3 Correct 50 ms 30788 KB Output is correct
4 Correct 52 ms 30788 KB Output is correct
5 Correct 44 ms 30788 KB Output is correct
6 Correct 41 ms 30788 KB Output is correct
7 Correct 46 ms 30788 KB Output is correct
8 Correct 49 ms 30788 KB Output is correct
9 Correct 39 ms 30788 KB Output is correct
10 Correct 52 ms 30788 KB Output is correct