Submission #12076

# Submission time Handle Problem Language Result Execution time Memory
12076 2014-12-20T23:07:06 Z ainta 배낭 문제 준비하기 (GA9_invknapsack) C++
0 / 100
0 ms 1100 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
#define INF 1000000000000000000LL
long long K, D[320];
bool v[320];
struct A{
	int num;
	long long S;
	bool operator <(const A &p)const{
		return S < p.S;
	}
}P[320];
bool Do(int n){
	int i, C = n;
	long long S = K;
	for (i = n; i >= 0; i--){
		if (P[i].S == -1)break;
		v[i] = false;
		if (S >= P[i].S){
			S -= P[i].S;
			v[300 - P[i].num] = true;
			C++;
		}
	}
	if (!S){
		printf("%d %d\n", C, 300);
		for (i = 1; i <= n; i++)printf("1 ");
		for (i = 150; i <= 300; i++)if (v[i])printf("%d ", i);
		printf("\n");
		return true;
	}
	return false;
}
int main()
{
	int i, j, c;
	scanf("%lld", &K);
	for (i = 0; i <= 300; i++){
		for (j = i; j >= 1; j--){
			if (D[j] == -1 || D[j - 1] == -1){
				D[j] = -1;
				continue;
			}
			D[j] = D[j] + D[j - 1];
			if (D[j] > INF)D[j] = -1;
		}
		D[0] = 1;
		for (j = 0; j <= i; j++){
			P[j].S = D[j];
			P[j].num = j;
		}
		sort(P, P + i + 1);
		if (Do(i))break;
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1100 KB Output isn't correct - the number of ways is not correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -