답안 #601002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
601002 2022-07-21T09:58:50 Z MohammadAghil Kitchen (BOI19_kitchen) C++17
0 / 100
48 ms 40784 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) begin(x), end(x)
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     // #ifndef ONLINE_JUDGE
     //      freopen("in.in", "r", stdin);
     //      freopen("out.out", "w", stdout);
     // #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 300 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

int a[maxn], b[maxn], dp[maxn][maxn*maxn], nxt[maxn*maxn];
bitset<maxn*maxn> can;

int main(){ IOS();
     int n, m, k; cin >> n >> m >> k;
     rep(i,0,n) cin >> a[i];    
     rep(i,0,m) cin >> b[i];    
     
     rep(i,0,n) if(a[i] < k) return cout << "Impossible\n", 0;

     int s = 0;
     rep(i,0,n) s += a[i];

     vector<int> c;
     can[0] = true;
     rep(i,0,m) {
          if(b[i] >= n) c.pb(b[i]);
          else can |= can<<b[i];
     }

     int lst = -1;
     per(i,maxn*maxn-1,0){
          if(can[i]) lst = i;
          nxt[i] = lst;
     }
     
     // er(sz(c));

     rep(i,0,sz(c)) rep(j,0,maxn*maxn){
          if(!i){
               if(c[i] == j) dp[i][j] = 1;
               continue;
          }
          dp[i][j] = dp[i-1][j];
          if(j == c[i]) dp[i][j] = max(dp[i][j], 1);
          else if(j > c[i] && dp[i][j-c[i]]) dp[i][j] = max(dp[i][j], dp[i][j-c[i]]+1);
     }

     // rep(i,0,10) er(i, dp[sz(c)-1][i]);

     int ans = inf;
     rep(s1,0,maxn*maxn){
          if(!s1 || (sz(c) && dp[sz(c)-1][s1])){
               int v1 = n*(k-(s1?dp[sz(c)-1][s1]:0));
               int v2 = s - s1;
               int mx = max({v1, v2, 0});
               if(nxt[mx] + 1) ans = min(ans, s1 + nxt[mx]);
          }
     }

     if(ans == inf) cout << "Impossible\n";
     else cout << ans - s << '\n';
     return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1064 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 980 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1064 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 980 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 4 ms 2912 KB Output is correct
4 Correct 48 ms 40784 KB Output is correct
5 Incorrect 12 ms 11988 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 13420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1064 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 1 ms 980 KB Output isn't correct
9 Halted 0 ms 0 KB -