답안 #493507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493507 2021-12-11T18:59:15 Z codr0 Kitchen (BOI19_kitchen) C++14
100 / 100
218 ms 4184 KB
// Code by Parsa Eslami
     
#include <bits/stdc++.h>
//#define int long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define err(x) cerr<<#x<<" : "<<x<<'\n'
#define IMP "Impossible\n"
 
using namespace std;
const int N=300+3;
int n,m,k;
int F[N];
int C[N];
int S;
bitset<N*N> btl;
bitset<N*N> bth[N];
const int INF=1e7;
int sum;
int ps[N*N];
    
    int bs(int h,int x){
		int l=max(x-1,-1); int r=N*N;
		if(ps[N*N-1]-ps[l]==0) return INF;
		while(r-l>1){
			int mid=(r+l)/2;
			if(ps[mid]-ps[l]!=0) r=mid;
			else l=mid;
		}
		return r;
	}
    
    void pre(){
		btl[0]=1;
		FOR(i,1,m) if(C[i]<n){
			btl=btl|(btl<<C[i]);
		}
		
		bth[0][0]=1;
		FOR(i,1,m) if(C[i]>=n){
			FORR(h,i,1) bth[h]=bth[h]|(bth[h-1]<<C[i]);
		}
	}
    
    void solve(){
		FOR(t,0,m){
			ps[0]=bth[t][0];
			FOR(i,1,N*N-1) ps[i]=ps[i-1]+bth[t][i];
			int st=k*n-t*n;
			FOR(j,max(0,st),N*N-1)
				if(btl[j]){
					sum=min(sum,j+bs(t,S-j));
				}
		}
	}
    
	int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	bool ex=0;
	cin>>n>>m>>k;
	FOR(i,1,n){
		cin>>F[i];
		S+=F[i];
		if(F[i]<k){
			ex=1;
		}
	}
	int x0=0;
	FOR(i,1,m){
		cin>>C[i];
		sum+=C[i];
		x0+=min(C[i],n);
	}
	if(sum<S||x0<k*n||ex){
		cout<<IMP;
		exit(0);
	}
	pre();
	solve();
	cout<<sum-S<<'\n';
		
	return 0;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 6 ms 844 KB Output is correct
10 Correct 6 ms 844 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 6 ms 588 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 716 KB Output is correct
2 Correct 101 ms 716 KB Output is correct
3 Correct 150 ms 3952 KB Output is correct
4 Correct 218 ms 4184 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 86 ms 704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1156 KB Output is correct
2 Correct 15 ms 1160 KB Output is correct
3 Correct 16 ms 1088 KB Output is correct
4 Correct 16 ms 1100 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 6 ms 844 KB Output is correct
10 Correct 6 ms 844 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 6 ms 588 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 128 ms 716 KB Output is correct
15 Correct 101 ms 716 KB Output is correct
16 Correct 150 ms 3952 KB Output is correct
17 Correct 218 ms 4184 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 86 ms 704 KB Output is correct
20 Correct 17 ms 1156 KB Output is correct
21 Correct 15 ms 1160 KB Output is correct
22 Correct 16 ms 1088 KB Output is correct
23 Correct 16 ms 1100 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 144 ms 3052 KB Output is correct
26 Correct 169 ms 3308 KB Output is correct
27 Correct 81 ms 2488 KB Output is correct
28 Correct 162 ms 3420 KB Output is correct
29 Correct 208 ms 3452 KB Output is correct
30 Correct 173 ms 4064 KB Output is correct