# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
339290 |
2020-12-25T03:21:31 Z |
12tqian |
Kitchen (BOI19_kitchen) |
C++17 |
|
262 ms |
8556 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
4716 KB |
Output is correct |
7 |
Correct |
3 ms |
4716 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
4716 KB |
Output is correct |
7 |
Correct |
3 ms |
4716 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
5 ms |
5228 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
5 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
5760 KB |
Output is correct |
2 |
Correct |
20 ms |
5616 KB |
Output is correct |
3 |
Correct |
28 ms |
5632 KB |
Output is correct |
4 |
Correct |
262 ms |
6640 KB |
Output is correct |
5 |
Correct |
42 ms |
5864 KB |
Output is correct |
6 |
Correct |
14 ms |
5484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
5 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
4716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
3 ms |
4716 KB |
Output is correct |
7 |
Correct |
3 ms |
4716 KB |
Output is correct |
8 |
Correct |
4 ms |
5100 KB |
Output is correct |
9 |
Correct |
5 ms |
5228 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
5 ms |
5100 KB |
Output is correct |
14 |
Correct |
14 ms |
5760 KB |
Output is correct |
15 |
Correct |
20 ms |
5616 KB |
Output is correct |
16 |
Correct |
28 ms |
5632 KB |
Output is correct |
17 |
Correct |
262 ms |
6640 KB |
Output is correct |
18 |
Correct |
42 ms |
5864 KB |
Output is correct |
19 |
Correct |
14 ms |
5484 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
4 ms |
5100 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
5 ms |
5100 KB |
Output is correct |
24 |
Correct |
4 ms |
4716 KB |
Output is correct |
25 |
Correct |
6 ms |
5356 KB |
Output is correct |
26 |
Correct |
6 ms |
5356 KB |
Output is correct |
27 |
Correct |
13 ms |
6124 KB |
Output is correct |
28 |
Correct |
74 ms |
6764 KB |
Output is correct |
29 |
Correct |
56 ms |
8556 KB |
Output is correct |
30 |
Correct |
31 ms |
7148 KB |
Output is correct |