제출 #563963

#제출 시각아이디문제언어결과실행 시간메모리
563963dantoh000Two Dishes (JOI19_dishes)C++14
10 / 100
191 ms32156 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int INF = 1000000000000000000; int n,m; int a[200005], s[200005], p[200005]; int b[200005], t[200005], q[200005]; int pa[200005]; int pb[200005]; int pp[200005], pq[200005]; int mem[2005][2005]; int dp(int i, int j){ if (i == n+1 && j == m+1) return 0; if (mem[i][j] != -1) return mem[i][j]; int T = pa[i-1] + pb[j-1]; int ret = -INF; if (i != n+1){ ret = max(ret, dp(i+1, j) + ((T+a[i] <= s[i])?p[i]:0)); } if (j != m+1){ ret = max(ret, dp(i, j+1) + ((T+b[j] <= t[j])?q[j]:0)); } //printf("%d %d %d %d\n",i,j,T,ret); return mem[i][j] = ret; } main(){ scanf("%lld%lld",&n,&m); for (int i = 1; i <= n; i++){ scanf("%lld%lld%lld",&a[i],&s[i],&p[i]); pa[i] = pa[i-1] + a[i]; pp[i] = pp[i-1] + p[i]; } for (int i = 1; i <= m; i++){ scanf("%lld%lld%lld",&b[i],&t[i],&q[i]); pb[i] = pb[i-1] + b[i]; pq[i] = pq[i-1] + q[i]; } if (n <= 2000 && m <= 2000){ memset(mem,-1,sizeof(mem)); printf("%lld",dp(1,1)); } else{ if (s[0] > t[0]){ swap(n,m); swap(a,b); swap(s,t); swap(p,q); swap(pp,pq); swap(pa,pb); } int ans = -INF; int R = m; int curT = 0; int stopT = 0; for (int i = 1; i <= n; i++){ if (pa[i] <= s[1]) pp[i] = max(pp[i-1], pp[i]); else pp[i] = pp[i-1]; } for (int i = 0; i <= n; i++){ while (pa[i] + pb[R] > t[1]){ R--; } ans = max(ans, pp[i]+pq[R]); } printf("%lld",ans); } }

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

dishes.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      | ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:53:13: warning: unused variable 'curT' [-Wunused-variable]
   53 |         int curT = 0;
      |             ^~~~
dishes.cpp:54:13: warning: unused variable 'stopT' [-Wunused-variable]
   54 |         int stopT = 0;
      |             ^~~~~
dishes.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
dishes.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%lld%lld%lld",&a[i],&s[i],&p[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         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...