結果
| 問題 |
No.247 線形計画問題もどき
|
| コンテスト | |
| ユーザー |
158b
|
| 提出日時 | 2015-07-17 23:41:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,142 bytes |
| コンパイル時間 | 646 ms |
| コンパイル使用メモリ | 77,900 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-08 09:40:14 |
| 合計ジャッジ時間 | 1,989 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 WA * 2 |
ソースコード
#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;
}
158b