답안 #1069563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069563 2024-08-22T05:54:32 Z 김은성(#11131) Two Dishes (JOI19_dishes) C++17
0 / 100
10000 ms 31524 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1000009;
const ll INF = 1.557e18;
int ka[MAXN], kb[MAXN];
ll pa[MAXN], pb[MAXN];
ll dp[2][MAXN];
int main(){
	int n, m, i, j;
	scanf("%d %d", &n, &m);
	vector<ll> ta(n+1), sa(n+1), tb(m+1), sb(m+1);
	for(i=1; i<=n; i++){
		scanf("%lld %lld %lld", &ta[i], &sa[i], &pa[i]);
		ta[i] += ta[i-1];
	}
	for(i=1; i<=m; i++){
		scanf("%lld %lld %lld", &tb[i], &sb[i], &pb[i]);
		tb[i] += tb[i-1];
	}
	for(i=1; i<=n; i++){
		if(sa[i] < ta[i])
			pa[i] = 0;
		else
			ka[i] = upper_bound(tb.begin(), tb.end(), sa[i] - ta[i]) - tb.begin() - 1;
		//printf("pa[%d]=%d ka[%d]=%d\n", i, pa[i], i, ka[i]);
	}
	for(i=1; i<=m; i++){
		if(sb[i] < tb[i])
			pb[i] = 0;
		else
			kb[i] = upper_bound(ta.begin(), ta.end(), sb[i] - tb[i]) - ta.begin() - 1;
		//printf("pb[%d]=%d kb[%d]=%d\n", i, pb[i], i, kb[i]);
	}
	dp[0][0] = 0;
	for(i=0; i<=n; i++){
		for(j=(int)(i==0); j<=m; j++){
			dp[i%2][j] = -INF;
			if(i > 0)
				dp[i%2][j] = max(dp[(i-1)%2][j] + pa[i] * (int)(ka[i] <= j), dp[i%2][j]);
			if(j>0)
				dp[i%2][j] = max(dp[i%2][j-1] + pb[j] * (int)(kb[j] <= i), dp[i%2][j]);
		}
	}
	printf("%lld\n", dp[n%2][m]);
	return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
dishes.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%lld %lld %lld", &ta[i], &sa[i], &pa[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%lld %lld %lld", &tb[i], &sb[i], &pb[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10072 ms 31524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10072 ms 31524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10072 ms 31524 KB Time limit exceeded
2 Halted 0 ms 0 KB -