제출 #374183

#제출 시각아이디문제언어결과실행 시간메모리
374183Mamnoon_SiamTwo Dishes (JOI19_dishes)C++17
10 / 100
134 ms109676 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 2e3 + 3;

int n, m;
ll A[N], B[N], S[N], T[N], P[N], Q[N];
ll donburi[N][N], curry[N][N];
ll donburi_p[N][N], curry_p[N][N];
ll dp[N][N];

int main(int argc, char const *argv[])
{
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= n; ++i) {
    scanf("%lld %lld %lld", &A[i], &S[i], &P[i]);
  }
  for(int i = 1; i <= m; ++i) {
    scanf("%lld %lld %lld", &B[i], &T[i], &Q[i]);
  }
  for(ll i = 1, sum = 0; i <= n; ++i) {
    sum += A[i];
    if(sum <= S[i]) {
      int j = 0;
      ll sum2 = 0;
      while(j < m and sum + sum2 + B[j+1] <= S[i]) {
        sum2 += B[++j];
      }
      donburi[i][j] = P[i];
      debug(i, j, P[i]);
    }
  }
  for(ll i = 1, sum = 0; i <= m; ++i) {
    sum += B[i];
    if(sum <= T[i]) {
      int j = 0;
      ll sum2 = 0;
      while(j < n and sum + sum2 + A[j+1] <= T[i]) {
        sum2 += A[++j];
      }
      debug(j, i, Q[i]);
      curry[j][i] = Q[i];
    }
  }
  for(int i = 0; i <= n; ++i) {
    curry_p[i][0] = curry[i][0];
    for(int j = 1; j <= m; ++j)
      curry_p[i][j] = curry_p[i][j-1] + curry[i][j];
    donburi_p[i][m] = donburi[i][m];
    for(int j = m-1; j >= 0; --j) {
      donburi_p[i][j] = donburi_p[i][j+1] + donburi[i][j];
    }
  }

  function<void(ll&,ll)> chkmax = [](ll& x, ll y) {
    x = max(x, y);
  };

  for(int x = 0; x <= n; ++x) {
    for(int y = 0; y <= m; ++y) {
      chkmax(dp[x+1][y], curry_p[x+1][y] + donburi_p[x+1][y] + dp[x][y]);
      chkmax(dp[x][y+1], curry[x][y+1] + dp[x][y]);
    }
  }

  printf("%lld\n", dp[n][m]);

  return 0;
}
/*
* use std::array instead of std::vector, if u can
* overflow?
* array bounds
*/

컴파일 시 표준 에러 (stderr) 메시지

dishes.cpp: In function 'int main(int, const char**)':
dishes.cpp:55:20: warning: statement has no effect [-Wunused-value]
   55 | #define debug(...) 42
      |                    ^~
dishes.cpp:87:7: note: in expansion of macro 'debug'
   87 |       debug(i, j, P[i]);
      |       ^~~~~
dishes.cpp:55:20: warning: statement has no effect [-Wunused-value]
   55 | #define debug(...) 42
      |                    ^~
dishes.cpp:98:7: note: in expansion of macro 'debug'
   98 |       debug(j, i, Q[i]);
      |       ^~~~~
dishes.cpp:71:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
dishes.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |     scanf("%lld %lld %lld", &A[i], &S[i], &P[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   76 |     scanf("%lld %lld %lld", &B[i], &T[i], &Q[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...