답안 #366032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366032 2021-02-12T18:55:08 Z Yomapeed Kitchen (BOI19_kitchen) C++17
100 / 100
185 ms 216172 KB
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 3e2 + 2;
ll dp[N][N * N];
void chmax(ll& a, ll b){
    a = max(a, b);
} 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n, m, k;
        cin >> n >> m >> k;
        vector<ll> a(n), b(m);
        bool flag = true;
        ll sum = 0;
        ll sa = 0;
        for(i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < k){
                flag = false;
            }
            sum += a[i];
        }
        sa = sum;
        for(i = 0; i < m; i++){
            cin >> b[i];
            sum -= b[i];
        }
        if(sum > 0){
            flag = false;
        }
        if(m < k){
            flag = false;
        }
        if(!flag){
            cout << "Impossible\n";
            return 0;
        }
        for(i = 0; i < N; i++){
            for(j = 0; j < N * N; j++){
                dp[i][j] = -INF;
            }
        }
        dp[0][0] = 0;
        for(i = 0; i < m; i++){
            ll B = min(b[i], n);
            for(ll x = 0; x < N * N; x++){
                if(x - b[i] >= 0 && dp[i][x - b[i]] != -INF){
                    chmax(dp[i + 1][x], dp[i][x - b[i]] + B);
                }
                chmax(dp[i + 1][x], dp[i][x]);
            }
        }
        ll ans = INF;
        //cout << sa << endl;
        for(i = sa; i < N * N; i++){
            if(dp[m][i] >= n * k){
                //cout << i << " " << dp[m][i] << endl;
                ans = i - sa;
                break;
            }
        }
        if(ans == INF){
            cout << "Impossible\n";
            return 0;
        }
        cout << ans << endl;
    }
    return 0;
}

Compilation message

kitchen.cpp:4: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("O3")
      | 
kitchen.cpp:5: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 216044 KB Output is correct
2 Correct 115 ms 216108 KB Output is correct
3 Correct 122 ms 215916 KB Output is correct
4 Correct 115 ms 215956 KB Output is correct
5 Correct 115 ms 215916 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 216044 KB Output is correct
2 Correct 115 ms 216108 KB Output is correct
3 Correct 122 ms 215916 KB Output is correct
4 Correct 115 ms 215956 KB Output is correct
5 Correct 115 ms 215916 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 117 ms 216044 KB Output is correct
10 Correct 117 ms 215936 KB Output is correct
11 Correct 123 ms 216044 KB Output is correct
12 Correct 118 ms 215916 KB Output is correct
13 Correct 118 ms 215916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 215916 KB Output is correct
2 Correct 185 ms 215916 KB Output is correct
3 Correct 175 ms 216044 KB Output is correct
4 Correct 178 ms 215916 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 154 ms 216044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 215916 KB Output is correct
2 Correct 123 ms 215916 KB Output is correct
3 Correct 124 ms 216044 KB Output is correct
4 Correct 123 ms 215916 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 216044 KB Output is correct
2 Correct 115 ms 216108 KB Output is correct
3 Correct 122 ms 215916 KB Output is correct
4 Correct 115 ms 215956 KB Output is correct
5 Correct 115 ms 215916 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 117 ms 216044 KB Output is correct
10 Correct 117 ms 215936 KB Output is correct
11 Correct 123 ms 216044 KB Output is correct
12 Correct 118 ms 215916 KB Output is correct
13 Correct 118 ms 215916 KB Output is correct
14 Correct 167 ms 215916 KB Output is correct
15 Correct 185 ms 215916 KB Output is correct
16 Correct 175 ms 216044 KB Output is correct
17 Correct 178 ms 215916 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 154 ms 216044 KB Output is correct
20 Correct 138 ms 215916 KB Output is correct
21 Correct 123 ms 215916 KB Output is correct
22 Correct 124 ms 216044 KB Output is correct
23 Correct 123 ms 215916 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 151 ms 215916 KB Output is correct
26 Correct 164 ms 215916 KB Output is correct
27 Correct 147 ms 216044 KB Output is correct
28 Correct 170 ms 216172 KB Output is correct
29 Correct 168 ms 215916 KB Output is correct
30 Correct 181 ms 215936 KB Output is correct