Submission #895537

# Submission time Handle Problem Language Result Execution time Memory
895537 2023-12-30T08:06:59 Z thunopro Two Dishes (JOI19_dishes) C++14
15 / 100
177 ms 34144 KB
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long 
#define maxn 200009 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1 
#define right id<<1|1 
#define re exit(0); 
#define _lower(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()+1  

const int mod = 1e9+7 ; 
const int INF = 1e9 ; 
const int LOG = 18 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<ll> vl ; 
typedef vector<pii> vii ; 
 
void add ( int &a , int b ) 
{
	a += b ;
	if ( a < 0 ) a += mod ; 
	if ( a >= mod ) a -= mod ; 
}

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } 

void rf () 
{
	freopen ("bai1.inp","r",stdin) ; 
//	freopen ("bai1.out","w",stdout) ; 
}

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

int n , m ; 
struct para{
	int t ; 
	ll end ; 
	int score ;
} a [maxn] , b [maxn] ;

bool check_sub1 () 
{
	set <ll> S ; 
	for ( int i = 1 ; i <= n ; i ++ ) S . insert (a[i].end) ; 
	for ( int i = 1 ; i <= m ; i ++ ) S . insert (b[i].end) ; 
	return (S.size() == 1) ; 
}
void sub1 () 
{
	ll sum_scoreA [n+2] , sum_scoreB [m+2] ; 
	
	sum_scoreA [0] = 0 ; 
	sum_scoreB [0] = 0 ;
	for ( int i = 1 ; i <= n ; i ++ ) sum_scoreA [i] = sum_scoreA [i-1] + a [i].score ; 
	for ( int i = 1 ; i <= m ; i ++ ) sum_scoreB [i] = sum_scoreB [i-1] + b [i].score ;
	
	ll sum_timeA [n+2] , sum_timeB [m+2] ; 
	sum_timeA [0] = 0 ; 
	sum_timeB [0] = 0 ; 
	for ( int i = 1 ; i <= n ; i ++ ) sum_timeA [i] = sum_timeA [i-1] + a [i].t ; 
	for ( int i = 1 ; i <= m ; i ++ ) sum_timeB [i] = sum_timeB [i-1] + b [i].t ;
	
	int j = m ; 
	ll res = - 1e18 ; 
	ll special_time = a [1].end ; 
	
	for ( int i = 0 ; i <= n ; i ++ ) 
	{
		while ( j && sum_timeA [i] + sum_timeB [j] > special_time ) j -- ;
		if ( sum_timeA [i] + sum_timeB [j] <= special_time ) chkmax (res,sum_scoreA [i] + sum_scoreB [j] ) ; 
	}
	cout << res ; 
}
void sub2 () 
{
	
	ll sum_timeA [n+2] , sum_timeB [m+2] ; 
	sum_timeA [0] = 0 ; 
	sum_timeB [0] = 0 ; 
	for ( int i = 1 ; i <= n ; i ++ ) sum_timeA [i] = sum_timeA [i-1] + a [i].t ; 
	for ( int i = 1 ; i <= m ; i ++ ) sum_timeB [i] = sum_timeB [i-1] + b [i].t ; 
	
	ll dp [n+2][m+2] ;
	memset ( dp , -0x3f , sizeof dp ) ; 
	dp [0][0] = 0 ; 
	
	for ( int i = 0 ; i <= n ; i ++ ) 
	{
		for ( int j = 0 ; j <= m ; j ++ ) 
		{
			if ( i < n ) 
			{
				int score ; 
				if ( sum_timeA [i+1] + sum_timeB [j] <= a[i+1].end ) score = a[i+1].score ; 
				else score = 0 ; 
				chkmax (dp[i+1][j],dp[i][j]+score) ; 
			}
			if ( j < m ) 
			{
				int score ; 
				if ( sum_timeA [i] + sum_timeB [j+1] <= b [j+1].end ) score = b [j+1].score ; 
				else score = 0 ; 
				chkmax (dp[i][j+1],dp[i][j]+score) ; 
			}
		}
	}
	cout << dp [n][m] ; 
}
int main () 
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0) ; 
//	rf () ; 
	cin >> n >> m ; 
	for ( int i = 1 ; i <= n ; i ++ ) cin >> a [i].t >> a [i].end >> a [i].score ; 
	for ( int i = 1 ; i <= m ; i ++ ) cin >> b [i].t >> b [i].end >> b [i].score ; 
	
	if ( check_sub1 () ) sub1 () ; 
	else if ( n <= 2000 && m <= 2000 ) sub2 () ; 
	
}

// range , error , check speical , ... 
// find key , find key 
//'-std=c++11' stay hard 
// there is no tomorrow 

Compilation message

dishes.cpp: In function 'void rf()':
dishes.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 100 ms 15952 KB Output is correct
2 Correct 100 ms 15820 KB Output is correct
3 Correct 102 ms 15956 KB Output is correct
4 Correct 103 ms 15700 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 103 ms 28856 KB Output is correct
7 Correct 52 ms 16464 KB Output is correct
8 Correct 53 ms 15440 KB Output is correct
9 Correct 108 ms 30328 KB Output is correct
10 Correct 74 ms 23380 KB Output is correct
11 Correct 82 ms 23864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2592 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2592 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 31 ms 34140 KB Output is correct
18 Correct 26 ms 34140 KB Output is correct
19 Correct 30 ms 34144 KB Output is correct
20 Correct 29 ms 31836 KB Output is correct
21 Correct 28 ms 32860 KB Output is correct
22 Correct 30 ms 33864 KB Output is correct
23 Correct 30 ms 33880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2592 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 31 ms 34140 KB Output is correct
18 Correct 26 ms 34140 KB Output is correct
19 Correct 30 ms 34144 KB Output is correct
20 Correct 29 ms 31836 KB Output is correct
21 Correct 28 ms 32860 KB Output is correct
22 Correct 30 ms 33864 KB Output is correct
23 Correct 30 ms 33880 KB Output is correct
24 Incorrect 177 ms 28524 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2592 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 31 ms 34140 KB Output is correct
18 Correct 26 ms 34140 KB Output is correct
19 Correct 30 ms 34144 KB Output is correct
20 Correct 29 ms 31836 KB Output is correct
21 Correct 28 ms 32860 KB Output is correct
22 Correct 30 ms 33864 KB Output is correct
23 Correct 30 ms 33880 KB Output is correct
24 Incorrect 177 ms 28524 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2592 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 31 ms 34140 KB Output is correct
18 Correct 26 ms 34140 KB Output is correct
19 Correct 30 ms 34144 KB Output is correct
20 Correct 29 ms 31836 KB Output is correct
21 Correct 28 ms 32860 KB Output is correct
22 Correct 30 ms 33864 KB Output is correct
23 Correct 30 ms 33880 KB Output is correct
24 Incorrect 177 ms 28524 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 15952 KB Output is correct
2 Correct 100 ms 15820 KB Output is correct
3 Correct 102 ms 15956 KB Output is correct
4 Correct 103 ms 15700 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 103 ms 28856 KB Output is correct
7 Correct 52 ms 16464 KB Output is correct
8 Correct 53 ms 15440 KB Output is correct
9 Correct 108 ms 30328 KB Output is correct
10 Correct 74 ms 23380 KB Output is correct
11 Correct 82 ms 23864 KB Output is correct
12 Correct 0 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2592 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 31 ms 34140 KB Output is correct
29 Correct 26 ms 34140 KB Output is correct
30 Correct 30 ms 34144 KB Output is correct
31 Correct 29 ms 31836 KB Output is correct
32 Correct 28 ms 32860 KB Output is correct
33 Correct 30 ms 33864 KB Output is correct
34 Correct 30 ms 33880 KB Output is correct
35 Incorrect 177 ms 28524 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 15952 KB Output is correct
2 Correct 100 ms 15820 KB Output is correct
3 Correct 102 ms 15956 KB Output is correct
4 Correct 103 ms 15700 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 103 ms 28856 KB Output is correct
7 Correct 52 ms 16464 KB Output is correct
8 Correct 53 ms 15440 KB Output is correct
9 Correct 108 ms 30328 KB Output is correct
10 Correct 74 ms 23380 KB Output is correct
11 Correct 82 ms 23864 KB Output is correct
12 Correct 0 ms 2392 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2592 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 31 ms 34140 KB Output is correct
29 Correct 26 ms 34140 KB Output is correct
30 Correct 30 ms 34144 KB Output is correct
31 Correct 29 ms 31836 KB Output is correct
32 Correct 28 ms 32860 KB Output is correct
33 Correct 30 ms 33864 KB Output is correct
34 Correct 30 ms 33880 KB Output is correct
35 Incorrect 177 ms 28524 KB Output isn't correct
36 Halted 0 ms 0 KB -