답안 #123295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123295 2019-07-01T06:07:57 Z 이온조(#3019) Two Dishes (JOI19_dishes) C++14
15 / 100
220 ms 32452 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1LL * 1e18;
int A[1000009], B[1000009], P[1000009], Q[1000009];
long long S[1000009], T[1000009], PA[1000009], PB[1000009], PQ[1000009];
long long D[2009][2009];

long long go(int i, int j) {
	if(i == 0 && j == 0) return 0;
	if(D[i][j] != -1) return D[i][j];
	long long ret = -INF;
	if(i) ret = max(ret, go(i-1, j) + (PA[i] + PB[j] <= S[i] ? 1 : 0));
	if(j) ret = max(ret, go(i, j-1) + (PA[i] + PB[j] <= T[j] ? 1 : 0));
	return D[i][j] = ret;
}

int main() {
	int N, M; scanf("%d%d",&N,&M);
	for(int i=1; i<=N; i++) scanf("%d%lld%d", &A[i], &S[i], &P[i]);
	for(int i=1; i<=M; i++) scanf("%d%lld%d", &B[i], &T[i], &Q[i]);

	bool S1 = (S[1] == T[1]);
	for(int i=2; i<=N; i++) if(S[i] != S[i-1]) S1 = 0;
	for(int i=2; i<=M; i++) if(T[i] != T[i-1]) S1 = 0;
	if(S1) {
		for(int i=1; i<=M; i++) PB[i] = PB[i-1] + B[i], PQ[i] = PQ[i-1] + Q[i];
		long long x = S[1], ans = -INF, s = 0;
		for(int i=1; i<=N+1; i++) {
			if(x <= 0) break;
			int l = 0, r = M;
			while(l <= r) {
				int m = l+r >> 1;
				if(PB[m] <= x) l = m+1;
				else r = m-1;
			}
			if(i == N+1 || PB[l-1] + A[i] > x) ans = max(ans, s + PQ[l-1]);

			if(i == N+1) break;
			x -= A[i]; s += P[i];
		}
		printf("%lld", ans);
	}
	else if(N <= 2000 && M <= 2000) {
		for(int i=1; i<=N; i++) PA[i] = PA[i-1] + A[i];
		for(int i=1; i<=M; i++) PB[i] = PB[i-1] + B[i];
		memset(D, -1, sizeof(D));
		printf("%lld", go(N, M));
	}
	return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:33:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l+r >> 1;
             ~^~
dishes.cpp:19:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, M; scanf("%d%d",&N,&M);
            ~~~~~^~~~~~~~~~~~~~
dishes.cpp:20:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d%lld%d", &A[i], &S[i], &P[i]);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:21:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=M; i++) scanf("%d%lld%d", &B[i], &T[i], &Q[i]);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 9848 KB Output is correct
2 Correct 220 ms 9720 KB Output is correct
3 Correct 210 ms 9720 KB Output is correct
4 Correct 214 ms 9788 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 210 ms 9336 KB Output is correct
7 Correct 105 ms 6836 KB Output is correct
8 Correct 104 ms 3576 KB Output is correct
9 Correct 213 ms 9976 KB Output is correct
10 Correct 154 ms 9720 KB Output is correct
11 Correct 145 ms 9704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 31952 KB Output is correct
2 Correct 32 ms 31992 KB Output is correct
3 Correct 29 ms 31992 KB Output is correct
4 Correct 28 ms 31992 KB Output is correct
5 Correct 28 ms 32120 KB Output is correct
6 Correct 28 ms 31964 KB Output is correct
7 Correct 28 ms 31992 KB Output is correct
8 Correct 28 ms 31992 KB Output is correct
9 Correct 28 ms 31992 KB Output is correct
10 Correct 28 ms 31996 KB Output is correct
11 Correct 28 ms 31992 KB Output is correct
12 Correct 28 ms 31992 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 28 ms 31992 KB Output is correct
15 Correct 28 ms 31992 KB Output is correct
16 Correct 28 ms 31992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 31952 KB Output is correct
2 Correct 32 ms 31992 KB Output is correct
3 Correct 29 ms 31992 KB Output is correct
4 Correct 28 ms 31992 KB Output is correct
5 Correct 28 ms 32120 KB Output is correct
6 Correct 28 ms 31964 KB Output is correct
7 Correct 28 ms 31992 KB Output is correct
8 Correct 28 ms 31992 KB Output is correct
9 Correct 28 ms 31992 KB Output is correct
10 Correct 28 ms 31996 KB Output is correct
11 Correct 28 ms 31992 KB Output is correct
12 Correct 28 ms 31992 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 28 ms 31992 KB Output is correct
15 Correct 28 ms 31992 KB Output is correct
16 Correct 28 ms 31992 KB Output is correct
17 Correct 80 ms 32296 KB Output is correct
18 Correct 85 ms 32336 KB Output is correct
19 Correct 84 ms 32272 KB Output is correct
20 Correct 77 ms 32292 KB Output is correct
21 Correct 79 ms 32248 KB Output is correct
22 Correct 81 ms 32452 KB Output is correct
23 Correct 80 ms 32296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 31952 KB Output is correct
2 Correct 32 ms 31992 KB Output is correct
3 Correct 29 ms 31992 KB Output is correct
4 Correct 28 ms 31992 KB Output is correct
5 Correct 28 ms 32120 KB Output is correct
6 Correct 28 ms 31964 KB Output is correct
7 Correct 28 ms 31992 KB Output is correct
8 Correct 28 ms 31992 KB Output is correct
9 Correct 28 ms 31992 KB Output is correct
10 Correct 28 ms 31996 KB Output is correct
11 Correct 28 ms 31992 KB Output is correct
12 Correct 28 ms 31992 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 28 ms 31992 KB Output is correct
15 Correct 28 ms 31992 KB Output is correct
16 Correct 28 ms 31992 KB Output is correct
17 Correct 80 ms 32296 KB Output is correct
18 Correct 85 ms 32336 KB Output is correct
19 Correct 84 ms 32272 KB Output is correct
20 Correct 77 ms 32292 KB Output is correct
21 Correct 79 ms 32248 KB Output is correct
22 Correct 81 ms 32452 KB Output is correct
23 Correct 80 ms 32296 KB Output is correct
24 Incorrect 185 ms 6740 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 31952 KB Output is correct
2 Correct 32 ms 31992 KB Output is correct
3 Correct 29 ms 31992 KB Output is correct
4 Correct 28 ms 31992 KB Output is correct
5 Correct 28 ms 32120 KB Output is correct
6 Correct 28 ms 31964 KB Output is correct
7 Correct 28 ms 31992 KB Output is correct
8 Correct 28 ms 31992 KB Output is correct
9 Correct 28 ms 31992 KB Output is correct
10 Correct 28 ms 31996 KB Output is correct
11 Correct 28 ms 31992 KB Output is correct
12 Correct 28 ms 31992 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 28 ms 31992 KB Output is correct
15 Correct 28 ms 31992 KB Output is correct
16 Correct 28 ms 31992 KB Output is correct
17 Correct 80 ms 32296 KB Output is correct
18 Correct 85 ms 32336 KB Output is correct
19 Correct 84 ms 32272 KB Output is correct
20 Correct 77 ms 32292 KB Output is correct
21 Correct 79 ms 32248 KB Output is correct
22 Correct 81 ms 32452 KB Output is correct
23 Correct 80 ms 32296 KB Output is correct
24 Incorrect 185 ms 6740 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 31952 KB Output is correct
2 Correct 32 ms 31992 KB Output is correct
3 Correct 29 ms 31992 KB Output is correct
4 Correct 28 ms 31992 KB Output is correct
5 Correct 28 ms 32120 KB Output is correct
6 Correct 28 ms 31964 KB Output is correct
7 Correct 28 ms 31992 KB Output is correct
8 Correct 28 ms 31992 KB Output is correct
9 Correct 28 ms 31992 KB Output is correct
10 Correct 28 ms 31996 KB Output is correct
11 Correct 28 ms 31992 KB Output is correct
12 Correct 28 ms 31992 KB Output is correct
13 Correct 27 ms 31992 KB Output is correct
14 Correct 28 ms 31992 KB Output is correct
15 Correct 28 ms 31992 KB Output is correct
16 Correct 28 ms 31992 KB Output is correct
17 Correct 80 ms 32296 KB Output is correct
18 Correct 85 ms 32336 KB Output is correct
19 Correct 84 ms 32272 KB Output is correct
20 Correct 77 ms 32292 KB Output is correct
21 Correct 79 ms 32248 KB Output is correct
22 Correct 81 ms 32452 KB Output is correct
23 Correct 80 ms 32296 KB Output is correct
24 Incorrect 185 ms 6740 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 9848 KB Output is correct
2 Correct 220 ms 9720 KB Output is correct
3 Correct 210 ms 9720 KB Output is correct
4 Correct 214 ms 9788 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 210 ms 9336 KB Output is correct
7 Correct 105 ms 6836 KB Output is correct
8 Correct 104 ms 3576 KB Output is correct
9 Correct 213 ms 9976 KB Output is correct
10 Correct 154 ms 9720 KB Output is correct
11 Correct 145 ms 9704 KB Output is correct
12 Correct 67 ms 31952 KB Output is correct
13 Correct 32 ms 31992 KB Output is correct
14 Correct 29 ms 31992 KB Output is correct
15 Correct 28 ms 31992 KB Output is correct
16 Correct 28 ms 32120 KB Output is correct
17 Correct 28 ms 31964 KB Output is correct
18 Correct 28 ms 31992 KB Output is correct
19 Correct 28 ms 31992 KB Output is correct
20 Correct 28 ms 31992 KB Output is correct
21 Correct 28 ms 31996 KB Output is correct
22 Correct 28 ms 31992 KB Output is correct
23 Correct 28 ms 31992 KB Output is correct
24 Correct 27 ms 31992 KB Output is correct
25 Correct 28 ms 31992 KB Output is correct
26 Correct 28 ms 31992 KB Output is correct
27 Correct 28 ms 31992 KB Output is correct
28 Correct 80 ms 32296 KB Output is correct
29 Correct 85 ms 32336 KB Output is correct
30 Correct 84 ms 32272 KB Output is correct
31 Correct 77 ms 32292 KB Output is correct
32 Correct 79 ms 32248 KB Output is correct
33 Correct 81 ms 32452 KB Output is correct
34 Correct 80 ms 32296 KB Output is correct
35 Incorrect 185 ms 6740 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 9848 KB Output is correct
2 Correct 220 ms 9720 KB Output is correct
3 Correct 210 ms 9720 KB Output is correct
4 Correct 214 ms 9788 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 210 ms 9336 KB Output is correct
7 Correct 105 ms 6836 KB Output is correct
8 Correct 104 ms 3576 KB Output is correct
9 Correct 213 ms 9976 KB Output is correct
10 Correct 154 ms 9720 KB Output is correct
11 Correct 145 ms 9704 KB Output is correct
12 Correct 67 ms 31952 KB Output is correct
13 Correct 32 ms 31992 KB Output is correct
14 Correct 29 ms 31992 KB Output is correct
15 Correct 28 ms 31992 KB Output is correct
16 Correct 28 ms 32120 KB Output is correct
17 Correct 28 ms 31964 KB Output is correct
18 Correct 28 ms 31992 KB Output is correct
19 Correct 28 ms 31992 KB Output is correct
20 Correct 28 ms 31992 KB Output is correct
21 Correct 28 ms 31996 KB Output is correct
22 Correct 28 ms 31992 KB Output is correct
23 Correct 28 ms 31992 KB Output is correct
24 Correct 27 ms 31992 KB Output is correct
25 Correct 28 ms 31992 KB Output is correct
26 Correct 28 ms 31992 KB Output is correct
27 Correct 28 ms 31992 KB Output is correct
28 Correct 80 ms 32296 KB Output is correct
29 Correct 85 ms 32336 KB Output is correct
30 Correct 84 ms 32272 KB Output is correct
31 Correct 77 ms 32292 KB Output is correct
32 Correct 79 ms 32248 KB Output is correct
33 Correct 81 ms 32452 KB Output is correct
34 Correct 80 ms 32296 KB Output is correct
35 Incorrect 185 ms 6740 KB Output isn't correct
36 Halted 0 ms 0 KB -