Submission #644489

# Submission time Handle Problem Language Result Execution time Memory
644489 2022-09-24T17:59:25 Z amoorj Kitchen (BOI19_kitchen) C++17
Compilation error
0 ms 0 KB
//#pragma GCC optimize ("O3,unroll-loops,Ofast")
//#pragma GCC target ("avx2,bmi,bmi2,popcnt")
#include <bits/stdc++.h>
#define F first
#define pb push_back
#define sz size()
#define S second
using namespace std;
typedef long long int ll;

const int N = 303, INF = 2e9;
int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;

inline void init(){
	for(int i=0;i<N;i++)
		for(int j=0;j<N*N;j++)
			dp[i][j] = -INF;
}
inline void input(){
	cin >> n >> m >> k;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	for(int i=0;i<m;i++)
		cin >> b[i];
}
inline void solve(){
	dp[0][0] = 0;
	for(int i=0;i<m;i++){
		for(int j=0;j<N*N;j++){	
			dp[i+1][j] = dp[i][j];
			if(j >= b[i])
				dp[i+1][j] = max(dp[i+1][j], dp[i][j-b[i]] + min(b[i], n));
		}
	}
	for(int i=0;i<n;i++){
		if(a[i] < k){	
			cout << "Impossible";
			return;
		}
	}
	for(int j=0;j<N*N;j++){
		if(dp[m][j] >= n*k){
			cout << j - sum;
			if(j - sum < 0)
				assert(false);
			return;
		}
	}
	cout << "Impossible";
}
int main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	init();
	int queries = 1;
//	cin >> queries;
	while(queries--){
		input();
		solve();
	}
	return 0;
}
0
real	0m0.066s
user	0m0.035s
sys	0m0.031s

Press ENTER or type command to continue
//#pragma GCC optimize ("O3,unroll-loops,Ofast")
//#pragma GCC target ("avx2,bmi,bmi2,popcnt")
#include <bits/stdc++.h>
#define F first
#define pb push_back
#define sz size()
#define S second
using namespace std;
typedef long long int ll;

const int N = 303, INF = 2e9;
int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;

inline void init(){
	for(int i=0;i<N;i++)
		for(int j=0;j<N*N;j++)
			dp[i][j] = -INF;
}
inline void input(){
	cin >> n >> m >> k;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	for(int i=0;i<m;i++)
		cin >> b[i];
}
inline void solve(){
	dp[0][0] = 0;
	for(int i=0;i<m;i++){
		for(int j=0;j<N*N;j++){	
			dp[i+1][j] = dp[i][j];
			if(j >= b[i])
				dp[i+1][j] = max(dp[i+1][j], dp[i][j-b[i]] + min(b[i], n));
		}
	}
	for(int i=0;i<n;i++){
		if(a[i] < k){	
			cout << "Impossible";
			return;
		}
	}
	for(int j=sum;j<N*N;j++){
		if(dp[m][j] >= n*k){
			cout << j - sum;
			return;
		}
	}
	cout << "Impossible";
}
int main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	init();
	int queries = 1;
//	cin >> queries;
	while(queries--){
		input();
		solve();
	}
	return 0;
}

Compilation message

kitchen.cpp:66:1: error: expected unqualified-id before numeric constant
   66 | 0
      | ^
kitchen.cpp:82:11: error: redefinition of 'const int N'
   82 | const int N = 303, INF = 2e9;
      |           ^
kitchen.cpp:11:11: note: 'const int N' previously defined here
   11 | const int N = 303, INF = 2e9;
      |           ^
kitchen.cpp:82:20: error: redefinition of 'const int INF'
   82 | const int N = 303, INF = 2e9;
      |                    ^~~
kitchen.cpp:11:20: note: 'const int INF' previously defined here
   11 | const int N = 303, INF = 2e9;
      |                    ^~~
kitchen.cpp:83:5: error: redefinition of 'int n'
   83 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |     ^
kitchen.cpp:12:5: note: 'int n' previously declared here
   12 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |     ^
kitchen.cpp:83:7: error: redefinition of 'int k'
   83 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |       ^
kitchen.cpp:12:7: note: 'int k' previously declared here
   12 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |       ^
kitchen.cpp:83:9: error: redefinition of 'int m'
   83 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |         ^
kitchen.cpp:12:9: note: 'int m' previously declared here
   12 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |         ^
kitchen.cpp:83:11: error: redefinition of 'int a [303]'
   83 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |           ^
kitchen.cpp:12:11: note: 'int a [303]' previously declared here
   12 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |           ^
kitchen.cpp:83:16: error: redefinition of 'int b [303]'
   83 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |                ^
kitchen.cpp:12:16: note: 'int b [303]' previously declared here
   12 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |                ^
kitchen.cpp:83:21: error: redefinition of 'int dp [303][91809]'
   83 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |                     ^~
kitchen.cpp:12:21: note: 'int dp [303][91809]' previously declared here
   12 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |                     ^~
kitchen.cpp:83:32: error: redefinition of 'int sum'
   83 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |                                ^~~
kitchen.cpp:12:32: note: 'int sum' previously defined here
   12 | int n,k,m,a[N],b[N],dp[N][N*N],sum = 0;
      |                                ^~~
kitchen.cpp:85:13: error: redefinition of 'void init()'
   85 | inline void init(){
      |             ^~~~
kitchen.cpp:14:13: note: 'void init()' previously defined here
   14 | inline void init(){
      |             ^~~~
kitchen.cpp:90:13: error: redefinition of 'void input()'
   90 | inline void input(){
      |             ^~~~~
kitchen.cpp:19:13: note: 'void input()' previously defined here
   19 | inline void input(){
      |             ^~~~~
kitchen.cpp:99:13: error: redefinition of 'void solve()'
   99 | inline void solve(){
      |             ^~~~~
kitchen.cpp:28:13: note: 'void solve()' previously defined here
   28 | inline void solve(){
      |             ^~~~~
kitchen.cpp:122:5: error: redefinition of 'int main()'
  122 | int main(){
      |     ^~~~
kitchen.cpp:53:5: note: 'int main()' previously defined here
   53 | int main(){
      |     ^~~~