Submission #130169
Source Code Expand
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <climits>
#include <sstream>
#include <functional>
#include <complex>
using namespace std;
#define len(array) (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define Rep(i, e) for(int i = 0;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define Rrep(i, e) for(int i = e;0 <= i;i--)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
#define pb push_back
#define rg(i, s, t) s <= i && i < t
//#define X real()
//#define Y imag()
//typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
//typedef complex<double> p;
const int INF = (int)2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const int weight[] = {0,1,10,100,1000,10000,100000,1000000,10000000};
//priority_queue< int, vector<int>, greater<int> > q;
// #define MAX_N 1000
int n, x, w[33], ptr;
P ary[33];
bool memo[50000000];
ll combi[1001][1001]; //aCb = combi[a][b]
int MAX_N = 50;
void makeCombi(){
afill2(combi, 0, double);
rep(i, 0, MAX_N+1) combi[i][0] = 1;
rep(i, 1, MAX_N+1){
rep(j, 1, i+1) combi[i][j] = combi[i-1][j-1] + combi[i-1][j];
}
}
ll rec(int pos, ll sum, ll remSum){
ll ret = 0;
// printf("pos = %d, sum = %lld, rem = %lld, ret1 = %lld\n", pos, sum, remSum, ret);
if(sum == x) return 1;
else if(sum > x) return 0;
else if(remSum < x - sum) return ret;
else if(pos == ptr) return 0;
Rep(i, ary[pos].second+1){
ret += combi[ary[pos].second][i] * rec(pos + 1, sum + ary[pos].first * i, remSum - ary[pos].first * i);
}
// ret += rec(pos + 1, sum + w[pos], remSum - w[pos]);
// ret += rec(pos + 1, sum, remSum - w[pos]);
// printf("pos = %d, sum = %lld, rem = %lld, ret2 = %lld\n", pos, sum, remSum, ret);
return ret;
}
void doIt(){
ll sum = 0;
makeCombi();
// cout << combi[32][16] << endl;
cin >> n >> x;
Rep(i, n){
cin >> w[i];
sum += w[i];
}
int prev = -1, p = 0, num = 1;
ptr = 0;
sort(w, w+n, greater<int>());
while(p < n){
if(prev == w[p]){
num++;
}
else{
if(prev != -1){
ary[ptr] = P(prev, num);
// printf("prev = %d, num = %d\n", prev, num);
ptr++;
}
num = 1;
}
prev = w[p];
p++;
}
if(prev != -1){
ary[ptr] = P(prev, num);
// printf("prev = %d, num = %d\n", prev, num);
ptr++;
}
cout << rec(0, 0, sum) << endl;
}
int main() {
doIt();
return 0;
}
Submission Info
Submission Time |
|
Task |
C - 無駄なものが嫌いな人 |
User |
mkiken |
Language |
C++ (G++ 4.6.4) |
Score |
0 |
Code Size |
3253 Byte |
Status |
TLE |
Exec Time |
2032 ms |
Memory |
8752 KB |
Judge Result
Set Name |
All |
Score / Max Score |
0 / 100 |
Status |
|
Set Name |
Test Cases |
All |
max_1.txt, max_2.txt, max_3.txt, max_4.txt, pair_1.txt, pair_2.txt, power2_1.txt, power2_2.txt, power2_3.txt, power2_4.txt, power2_5.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt |
Case Name |
Status |
Exec Time |
Memory |
max_1.txt |
AC |
34 ms |
8720 KB |
max_2.txt |
TLE |
2031 ms |
8632 KB |
max_3.txt |
AC |
34 ms |
8604 KB |
max_4.txt |
TLE |
2031 ms |
8748 KB |
pair_1.txt |
TLE |
2031 ms |
8744 KB |
pair_2.txt |
AC |
392 ms |
8616 KB |
power2_1.txt |
AC |
611 ms |
8624 KB |
power2_2.txt |
AC |
61 ms |
8620 KB |
power2_3.txt |
AC |
33 ms |
8616 KB |
power2_4.txt |
AC |
34 ms |
8616 KB |
power2_5.txt |
AC |
1191 ms |
8616 KB |
random_1.txt |
TLE |
2032 ms |
8752 KB |
random_2.txt |
TLE |
2032 ms |
8640 KB |
random_3.txt |
AC |
60 ms |
8604 KB |
random_4.txt |
TLE |
2032 ms |
8748 KB |
random_5.txt |
AC |
869 ms |
8608 KB |
random_6.txt |
TLE |
2032 ms |
8744 KB |
random_7.txt |
TLE |
2031 ms |
8740 KB |
random_8.txt |
TLE |
2029 ms |
8740 KB |
random_9.txt |
AC |
1282 ms |
8628 KB |
sample_1.txt |
AC |
34 ms |
8620 KB |
sample_2.txt |
AC |
32 ms |
8608 KB |
sample_3.txt |
AC |
34 ms |
8616 KB |
sample_4.txt |
AC |
32 ms |
8612 KB |
small_1.txt |
AC |
34 ms |
8608 KB |
small_2.txt |
AC |
34 ms |
8672 KB |
small_3.txt |
AC |
32 ms |
8612 KB |
small_4.txt |
AC |
36 ms |
8608 KB |