結果

問題 No.247 線形計画問題もどき
ユーザー 158b158b
提出日時 2015-07-17 23:41:24
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,142 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 77,468 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-22 18:25:31
合計ジャッジ時間 2,156 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 14 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 318 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 26 ms
4,376 KB
testcase_25 AC 30 ms
4,384 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
using namespace std;

//#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vecy[4] = {0,-1,0,1};
const int Vecx[4] = {1,0,-1,0};

int x[100] = {0};
int total,n;
int a[100] = {0};

bool func(int op, int left, int &ans){
	if(left == 0){
		ans = min(ans, accumulate(x, x+n, 0));
		return true;
	}
	
	if(op >= n){
		return false;
	}
	
	x[op] = left / a[op];
	
	if(ans == INT_MAX){
		for(int i=0; i<6; i++){
			func(op+1, left - a[op] * x[op], ans);
			if(x[op] == 0){
				break;
			}
			x[op] --;
		}
		return false;
	}else{
		for(int i=0; i<4; i++){
			func(op+1, left - a[op] * x[op], ans);
			if(x[op] == 0){
				break;
			}
			x[op] --;
		}
		return false;
	}
}

int main(){
	int ans = INT_MAX;
	
	cin >> total >> n;
	rep(i,n){
		cin >> a[i];
	}
	
	sort(a, a + n, greater<int>());  	//降順
	
	func(0, total, ans);
	cout << (ans == INT_MAX ? -1 : ans) << endl;
	
    return 0;
}
0