Submission #3437198


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,K;
ll A[20];
ll dp[1<<18];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>N>>K;
  rep(i,N)cin>>A[i];
  dp[0]=1;
  rep(S,(1<<N)-1){
    ll k=0;
    while((S>>k)&1)k++;
    dp[S|(1<<k)]+=dp[S];

    repl(i,k+1,N){
      if((S>>i)&1)continue;
      if(A[i]+A[k]>K*2)continue;
      dp[S|(1<<i)|(1<<k)]+=dp[S];
    }

    repl(i,k+1,N)repl(j,i+1,N){
      if((S>>i)&1)continue;
      if((S>>j)&1)continue;
      if(A[i]+A[j]+A[k]>K*3)continue;
      dp[S|(1<<i)|(1<<j)|(1<<k)]+=dp[S];
    }
  }
  cout<<dp[(1<<N)-1]<<endl;

  return 0;
}

Submission Info

Submission Time
Task F - Team Making
User SyntaxSato
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1216 Byte
Status AC
Exec Time 97 ms
Memory 2304 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 42
Set Name Test Cases
Sample 01_sample_01, 01_sample_02, 01_sample_03
All 01_sample_01, 01_sample_02, 01_sample_03, 02_handmake_01, 02_handmake_02, 02_handmake_03, 02_handmake_04, 02_handmake_05, 02_handmake_06, 02_handmake_07, 02_handmake_08, 02_handmake_09, 03_manual_01, 03_manual_02, 03_manual_03, 03_manual_04, 03_manual_05, 03_manual_06, 03_manual_07, 03_manual_08, 03_manual_09, 03_manual_10, 03_manual_11, 03_manual_12, 03_manual_13, 03_manual_14, 03_manual_15, 03_manual_16, 03_manual_17, 03_manual_18, 03_manual_19, 03_manual_20, 04_rand_01, 04_rand_02, 04_rand_03, 04_rand_04, 04_rand_05, 04_rand_06, 04_rand_07, 04_rand_08, 04_rand_09, 04_rand_10
Case Name Status Exec Time Memory
01_sample_01 AC 1 ms 256 KiB
01_sample_02 AC 1 ms 256 KiB
01_sample_03 AC 2 ms 256 KiB
02_handmake_01 AC 1 ms 256 KiB
02_handmake_02 AC 96 ms 2304 KiB
02_handmake_03 AC 1 ms 256 KiB
02_handmake_04 AC 1 ms 256 KiB
02_handmake_05 AC 1 ms 256 KiB
02_handmake_06 AC 1 ms 256 KiB
02_handmake_07 AC 94 ms 2304 KiB
02_handmake_08 AC 43 ms 1280 KiB
02_handmake_09 AC 92 ms 2304 KiB
03_manual_01 AC 89 ms 2304 KiB
03_manual_02 AC 89 ms 2304 KiB
03_manual_03 AC 89 ms 2304 KiB
03_manual_04 AC 89 ms 2304 KiB
03_manual_05 AC 91 ms 2304 KiB
03_manual_06 AC 89 ms 2304 KiB
03_manual_07 AC 88 ms 2304 KiB
03_manual_08 AC 89 ms 2304 KiB
03_manual_09 AC 89 ms 2304 KiB
03_manual_10 AC 89 ms 2304 KiB
03_manual_11 AC 89 ms 2304 KiB
03_manual_12 AC 89 ms 2304 KiB
03_manual_13 AC 95 ms 2304 KiB
03_manual_14 AC 96 ms 2304 KiB
03_manual_15 AC 94 ms 2304 KiB
03_manual_16 AC 93 ms 2304 KiB
03_manual_17 AC 94 ms 2304 KiB
03_manual_18 AC 93 ms 2304 KiB
03_manual_19 AC 97 ms 2304 KiB
03_manual_20 AC 97 ms 2304 KiB
04_rand_01 AC 20 ms 768 KiB
04_rand_02 AC 93 ms 2304 KiB
04_rand_03 AC 44 ms 1280 KiB
04_rand_04 AC 20 ms 768 KiB
04_rand_05 AC 21 ms 768 KiB
04_rand_06 AC 10 ms 512 KiB
04_rand_07 AC 21 ms 768 KiB
04_rand_08 AC 22 ms 768 KiB
04_rand_09 AC 11 ms 512 KiB
04_rand_10 AC 44 ms 1280 KiB