Submission #530432

#TimeUsernameProblemLanguageResultExecution timeMemory
530432Killer2501Kitchen (BOI19_kitchen)C++14
100 / 100
25 ms708 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 3e2+5; const int M = 1e2+2; const int mod = 1e9+7; const ll base = 75; const int inf = 1e9; int m, n, t, b[N], d[N], lab[N*N]; int k, a[N], dp[N*N]; ll ans, tong; vector<int> adj[N]; vector<pii> vi; string s[N]; bool vis[N]; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n&1)total = total * k % mod; k = k * k % mod; } return total; } void add(int &x, int y) { x += y; if(x >= mod)x -= mod; } int findp(int u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); } void hop(int u, int v) { u = findp(u); v = findp(v); if(u == v)return; if(lab[u] > lab[v])swap(u, v); lab[u] += lab[v]; lab[v] = u; } void sol() { cin >> n >> m >> k; for(int i = 1; i <= n; i ++) { cin >> a[i]; tong += a[i]; } for(int i = 1; i <= m; i ++)cin >> b[i]; fill_n(dp, N*N, -1); sort(a+1, a+1+n); if(a[1] < k) { cout << "Impossible"; return; } dp[0] = 0; for(int i = 1; i <= m; i ++) { t = min(b[i], n); for(int j = N*N-1; j >= b[i]; j --) if(dp[j-b[i]] != -1)dp[j] = max(dp[j], dp[j-b[i]]+t); } for(int i = tong; i < N*N; i ++) { if(dp[i] >= n*k) { cout << i-tong; return; } } cout << "Impossible"; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; while(test -- > 0)sol(); return 0; }

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:93:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...