Submission #339290

#TimeUsernameProblemLanguageResultExecution timeMemory
33929012tqianKitchen (BOI19_kitchen)C++17
100 / 100
262 ms8556 KiB
#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; const double PI = 4 * atan(1); #define sz(x) (int)(x).size() #define ll long long #define ld long double #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair <int, int> #define vi vector<int> #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define vpi vector<pair<int, int>> #define vpd vector<pair<double, double>> #define pd pair<double, double> #define f0r(i,a) for(int i=0;i<a;i++) #define f1r(i,a,b) for(int i=a;i<b;i++) #define trav(a, x) for (auto& a : x) template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]"; } void fast_io(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } void io(string taskname){ string fin = taskname + ".in"; string fout = taskname + ".out"; const char* FIN = fin.c_str(); const char* FOUT = fout.c_str(); freopen(FIN, "r", stdin); // freopen(FOUT, "w", stdout); fast_io(); } const int MAX = 3e2 + 5; vi v1; vi v2; int get1[MAX*MAX]; int get2[MAX*MAX]; set<int> t[MAX*MAX]; int main(){ fast_io(); // io("test"); int n, m, k; cin >> n >> m >> k; // cout << n << " " << " " << m << " " << k << endl; int sum = 0; bool ok = false; f0r(i, n){ int ai; cin >> ai; sum += ai; if(ai<k){ ok = true; }//cout << i << endl; } //return 0; if(sum>= MAX*MAX){ cout << "Impossible" << endl; return 0; } int bound = n*k; // cout << "here" << endl; f0r(i, m){ int bi; cin >> bi; if(bi<=n){ v1.eb(bi); } else v2.eb(bi); } //return 0; if(ok){ cout << "Impossible" << endl; return 0; } sort(all(v1)); sort(all(v2)); vi pos; pos.eb(0); get1[0] = 1; f0r(i, sz(v1)){ vi tmp; for(int x: pos){ int nxt = v1[i] + x; if(get1[nxt] == 0){ tmp.eb(nxt); } } for(int x: tmp){ pos.eb(x); get1[x] = 1; } } pos.clear(); pos.eb(0); f0r(i, MAX*MAX) get2[i] = -1; get2[0] = 0; f0r(i, sz(v2)){ vi tmp; for(int x: pos){ int nxt = v2[i] + x; if(get2[nxt] == -1){ tmp.eb(nxt); } } for(int x: pos){ int nxt = v2[i] + x; get2[nxt] = max(get2[nxt], 1 + get2[x]); //if(nxt == 356) cout << get2[nxt]<< " here" << endl; } for(int x: tmp){ pos.eb(x); } } // cout << pos << endl; f0r(i, MAX*MAX){ if(get2[i] == -1) continue; // cout << i << " asdf " << get2[i] << endl; t[get2[i]].insert(i); } int ans = MAX*MAX; f0r(i, MAX*MAX){ if(get1[i] == 0) continue; int need = ceil(((double)(bound - i))/n); if(i>= sum && i >= bound){ // cout << "here" << endl; // cout << i << " adsf" << endl; ans = min(ans, i); continue; } // cout << need << endl; // cout << need << endl; f1r(j, max(need, 0), MAX){ if(sz(t[j]) == 0) continue; int left = sum - i; // cout << "here" << " " << sz(t[j]) << endl; auto it = t[j].lb(left); // cout << sz(t[j]) << endl; // cout << left << " lb" << endl; if(it != t[j].end()){ // cout << i <<" asdf" << endl; ans = min(ans, i +(*it)); } } } if(ans == MAX*MAX) { cout << "Impossible" << endl; return 0; } cout << ans - sum<< endl; return 0; }

Compilation message (stderr)

kitchen.cpp:1: warning: ignoring #pragma comment  [-Wunknown-pragmas]
    1 | #pragma comment(linker, "/stack:200000000")
      | 
kitchen.cpp: In function 'void io(std::string)':
kitchen.cpp:51:17: warning: unused variable 'FOUT' [-Wunused-variable]
   51 |     const char* FOUT = fout.c_str();
      |                 ^~~~
kitchen.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   52 |     freopen(FIN, "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...