답안 #726862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726862 2023-04-19T13:09:16 Z TimDee Kitchen (BOI19_kitchen) C++17
21 / 100
1000 ms 3156 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,popcnt")

//#define int long long
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define s second
#define pi pair<int,int>

#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];

const int inf = 1e9;
const int S=90000;
const int M=300;
bitset<S+1> dp;
bitset<S+1> dp2[M+1];

void solve() {

	int n,m,k; cin>>n>>m>>k;
	vii(a,n);
	vii(b,m);

	if (k>m) {
		cout<<"Impossible";
		return;
	}
	forn(i,n) if (a[i]<k) {
		cout<<"Impossible";
		return;
	}
	int s=0;
	for(auto&x:a) s+=x;
	for(auto&x:b) s-=x;
	if (s>0) {
		cout<<"Impossible";
		return;
	}

	s=0;
	for(auto&x:a) s+=x;

	int ans=inf;

	dp[0]=1;
	for(auto&x:b) {
		if (x>=n) continue;
		dp|=dp<<x;
	}
	dp2[0][0]=1;
	for(auto&x:b) {
		if (x<n) continue;
		for (int j=m-1; j>=0; --j) {
			dp2[j+1]|=dp2[j]<<x;
		}
	}
	for (int j=m-1; j>=0; --j) dp2[j]|=dp2[j+1];

	for (int i=0; i<=s; ++i) {
		if (!dp[i]) continue;
		int x=max(k-i/n,0);
		for (int j=s-i; j<=S; ++j) {
			if (dp2[x][j]) ans=min(ans,i+j-s);
		}
	}

	if (ans==inf) cout<<"Impossible";
	else cout<<ans;

}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 3156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 30 ms 724 KB Output is correct
3 Correct 123 ms 788 KB Output is correct
4 Correct 115 ms 792 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -