結果
| 問題 |
No.247 線形計画問題もどき
|
| コンテスト | |
| ユーザー |
158b
|
| 提出日時 | 2015-07-17 23:16:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,009 bytes |
| コンパイル時間 | 699 ms |
| コンパイル使用メモリ | 77,604 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-08 09:30:08 |
| 合計ジャッジ時間 | 1,624 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 17 WA * 6 |
ソースコード
#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[100000] = {0};
int total,n;
int a[100000] = {0};
bool func(int op, int left, int &ans){
if(left == 0){
ans = accumulate(x, x+n, 0);
return true;
}
if(op >= n){
return false;
}
x[op] = left / a[op];
while(x[op] >= 0){
if(func(op+1, left - a[op] * x[op], ans)){
return true;
}
if(x[op] == 0){
return false;
}
x[op] --;
}
x[op] = 0;
return false;
}
int main(){
int ans = 0;
cin >> total >> n;
rep(i,n){
cin >> a[i];
}
sort(a, a + n, greater<int>()); //降順
if(func(0, total, ans)){
cout << ans << endl;
}else{
cout << -1 << endl;
}
return 0;
}
158b