Submission #490299

# Submission time Handle Problem Language Result Execution time Memory
490299 2021-11-26T20:11:12 Z robell Kitchen (BOI19_kitchen) C++14
100 / 100
27 ms 676 KB
/*
Problem: 
Problem Link: 
Notes: 
*/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define f first
#define s second
int mod=1e9+7;
inline void rv(int &n){
    n=0;int m=1;char c=getchar_unlocked();
    if (c=='-'){m=-1; c=getchar_unlocked();}
    for (;c>47 && c<58;c=getchar_unlocked()){n=n*(1<<1)+n*(1<<3)+c-48;}
    n*=m;
}
inline void rv(ll &n){
    n=0;int m=1;char c=getchar_unlocked();
    if (c=='-'){m=-1; c=getchar_unlocked();}
    for (;c>47 && c<58;c=getchar_unlocked()){n=n*(1<<1)+n*(1<<3)+c-48;}
    n*=m;
}
inline void rv(double &n){
    n=0;int m=1;char c=getchar_unlocked();
    if (c=='-'){m=-1; c=getchar_unlocked();}
    for (;c>47 && c<58;c=getchar_unlocked()){n=n*(1<<1)+n*(1<<3)+c-48;}
    if (c=='.'){
        double p = 0.1;c=getchar_unlocked();
        for (;c>47 && c<58;c=getchar_unlocked()){n+=((c-48)*p);p/=10;}
    }
    n*=m;
}
inline void rv(float &n){
    n=0;int m=1;char c=getchar_unlocked();
    if (c=='-'){m=-1; c=getchar_unlocked();}
    for (;c>47 && c<58;c=getchar_unlocked()){n=n*(1<<1)+n*(1<<3)+c-48;}
    if (c=='.'){
        double p = 0.1;c=getchar_unlocked();
        for (;c>47 && c<58;c=getchar_unlocked()){n+=((c-48)*p);p/=10;}
    }
    n*=m;
}
inline void rv(string &w){
    w="";char c=getchar_unlocked();
    while (c!=' '&&c!='\n'&&c!=EOF){w+=c;c=getchar_unlocked();}
}
inline void rv(char &c){c=getchar_unlocked();}
template<typename T, typename ...Types>
void rv(T &n, Types&&... args){rv(n);rv(args...);}
void setIO(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void setIO(string f){
	freopen((f+".in").c_str(),"r",stdin);
	freopen((f+".out").c_str(),"w",stdout);
	setIO();
}
int N, M, K, a[(int)300], b[(int)300], dp[90300];
int main(){
	setIO();cin >> N >> M >> K;
    for (int i=0;i<N;i++) cin >> a[i];
    for (int i=0;i<M;i++) cin >> b[i];
    int sum = 0;
    int minv = 1e9;for (int i=0;i<N;i++) minv=min(minv,a[i]), sum+=a[i];
    if (minv<K){cout << "Impossible\n";return 0;}
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for (int i=0;i<M;i++){
        for (int j=90300-b[i]-1;j>=0;j--){
            if (dp[j]!=(-1)){
                dp[j+b[i]]=max(dp[j+b[i]],dp[j]+min(b[i],N));
            }
        }
    }
    int v = 1e9;
    for (int i=sum;i<90300;i++){
        if (dp[i]>=N*K){
            v=min(v,i-sum);
        }
    }
    cout << ((v==1e9)?"Impossible":to_string(v)) << "\n";
}

Compilation message

kitchen.cpp: In function 'void setIO(std::string)':
kitchen.cpp:65:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:66:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 572 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 588 KB Output is correct
2 Correct 16 ms 588 KB Output is correct
3 Correct 23 ms 676 KB Output is correct
4 Correct 27 ms 668 KB Output is correct
5 Correct 24 ms 672 KB Output is correct
6 Correct 15 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 588 KB Output is correct
2 Correct 3 ms 576 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 572 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 19 ms 588 KB Output is correct
15 Correct 16 ms 588 KB Output is correct
16 Correct 23 ms 676 KB Output is correct
17 Correct 27 ms 668 KB Output is correct
18 Correct 24 ms 672 KB Output is correct
19 Correct 15 ms 672 KB Output is correct
20 Correct 6 ms 588 KB Output is correct
21 Correct 3 ms 576 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 14 ms 588 KB Output is correct
26 Correct 18 ms 588 KB Output is correct
27 Correct 11 ms 588 KB Output is correct
28 Correct 19 ms 588 KB Output is correct
29 Correct 26 ms 672 KB Output is correct
30 Correct 26 ms 672 KB Output is correct