답안 #530432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530432 2022-02-25T10:41:27 Z Killer2501 Kitchen (BOI19_kitchen) C++14
100 / 100
25 ms 708 KB
#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

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);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 704 KB Output is correct
2 Correct 16 ms 588 KB Output is correct
3 Correct 21 ms 588 KB Output is correct
4 Correct 22 ms 708 KB Output is correct
5 Correct 25 ms 700 KB Output is correct
6 Correct 15 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 588 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 4 ms 588 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 17 ms 704 KB Output is correct
15 Correct 16 ms 588 KB Output is correct
16 Correct 21 ms 588 KB Output is correct
17 Correct 22 ms 708 KB Output is correct
18 Correct 25 ms 700 KB Output is correct
19 Correct 15 ms 588 KB Output is correct
20 Correct 3 ms 588 KB Output is correct
21 Correct 3 ms 592 KB Output is correct
22 Correct 4 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 14 ms 588 KB Output is correct
26 Correct 18 ms 588 KB Output is correct
27 Correct 12 ms 588 KB Output is correct
28 Correct 18 ms 708 KB Output is correct
29 Correct 19 ms 588 KB Output is correct
30 Correct 25 ms 688 KB Output is correct