結果

提出番号 2047
提出者 dohatsutsu
言語 C++
提出日時 2018-08-04 15:04:41
問題名 (66)Cut onion
結果 TLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 2ms 7824KB
2 AC 100% 2ms 8192KB
3 AC 100% 1ms 7824KB
4 AC 100% 2ms 8416KB
5 AC 100% 2ms 8128KB
6 AC 100% 2ms 8192KB
7 AC 100% 2ms 8448KB
8 AC 100% 98ms 8384KB
9 AC 100% 2ms 8176KB
10 AC 100% 51ms 8064KB
11 AC 100% 5ms 8176KB
12 AC 100% 2ms 7568KB
13 TLE 0% 5943ms 7776KB
14 AC 100% 1ms 8272KB
15 AC 100% 385ms 8176KB
16 AC 100% 2ms 8048KB
17 AC 100% 2ms 8096KB
18 AC 100% 208ms 8704KB
19 AC 100% 1027ms 8192KB
20 AC 100% 2ms 7504KB

ソースコード

#include<bits/stdc++.h>
using namespace std;
int N,K,B;
int A[16];

int limit;
bool dfs(int x,int c,int t[16],int sz,int cost){
  if(cost>limit)return false;
  if(x==N)return true;

  if( A[x] <= 0 )return dfs(x+1,c,t,sz,cost);
  
  int tmp[16];
  for(int i=0;i<sz;i++)tmp[i]=t[i];
  
  for(int i=0;i<sz;i++){
    int u=t[i];
    A[x] -= u;
    swap(t[i],t[sz-1]);
    if( dfs(x,c,t,sz-1,cost) )return true;
    A[x] += u;

    for(int j=0;j<sz;j++)t[j]=tmp[j];
      
    if(t[i]>A[x]){
      t[i]-=A[x];
      if( dfs(x+1,c,t,sz,cost+1) )return true;
      t[i]+=A[x];
    }
  }
  
  if(c>0){
    if( dfs(x+1, c-1,t,sz,cost) )return true;
    t[sz]=B-A[x];
    if( dfs(x+1, c-1,t,sz+1,cost+1) )return true;
  }

  return false;
}

int main(){
  cin>>N>>K>>B;
  for(int i=0;i<N;i++)cin>>A[i];
  int t[16];
  
  for( limit = 0; limit <=13; limit ++){
    if( dfs(0,K,t,0,0) ){
      cout<<limit<<endl;
      return 0;
    }
  }
  
  cout<<15<<endl;
  return 0;
}