結果

提出番号 2049
提出者 TangentDay
言語 C++
提出日時 2018-08-04 15:05:25
問題名 (66)Cut onion
結果 MLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 MLE 0% 50ms 342352KB
2 MLE 0% 55ms 342384KB
3 MLE 0% 51ms 342384KB
4 MLE 0% 54ms 344576KB
5 MLE 0% 50ms 342352KB
6 MLE 0% 46ms 343024KB
7 MLE 0% 13986ms 3491340KB
8 MLE 0% 196ms 400752KB
9 MLE 0% 130ms 369520KB
10 MLE 0% 2944ms 1097140KB
11 TLE 0% 20002ms 0KB
12 TLE 0% 20001ms 0KB
13 TLE 0% 20002ms 0KB
14 TLE 0% 20002ms 0KB
15 TLE 0% 20002ms 0KB
16 TLE 0% 20002ms 0KB
17 TLE 0% 20001ms 0KB
18 TLE 0% 20002ms 0KB
19 TLE 0% 20002ms 0KB
20 TLE 0% 20002ms 0KB

ソースコード

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

map<int, int> dp[18][100000];

int main() {
    int n, k, b;
    cin >> n >> k >> b;
    VI a(n);
    REP(i,n) a[i] = in();

    dp[0][0][0] = 0;
    REP(x,k) REP(mask,1<<n) for(P p : dp[x][mask]) {
        REP(i,n){
            if ((mask >> i) & 1) continue;
            int next = mask | (1 << i);
            if (p.first + a[i] <= b){
                if (!dp[x+1][next].count(0) || dp[x+1][next][0] > p.second) dp[x+1][next][0] = p.second;
            }
            if (p.first + a[i] < b){
                if (!dp[x][next].count(p.first + a[i]) || dp[x][next][p.first + a[i]] > p.second + 1){
                    dp[x][next][p.first + a[i]] = p.second + 1;
                }
            }
            if (p.first + a[i] > b){
                if (!dp[x+1][next].count(p.first + a[i] - b) || dp[x+1][next][p.first + a[i] - b] > p.second + 1){
                    dp[x+1][next][p.first + a[i] - b] = p.second + 1;
                }
                if (!dp[x+2][next].count(0) || dp[x+2][next][0] > p.second) dp[x+2][next][0] = p.second;
            }
        }
    }

    int ans = 100;
    REP(x,k+1){
        for (P p : dp[x][(1<<n)-1]) if (x < k || p.first == 0) ans = min(ans, p.second);
    }
    cout << ans << endl;

    return 0;
}