結果
問題 | No.385 カップ麺生活 |
ユーザー |
![]() |
提出日時 | 2016-07-01 22:55:27 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,637 bytes |
コンパイル時間 | 1,522 ms |
コンパイル使用メモリ | 163,996 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-04 22:25:17 |
合計ジャッジ時間 | 2,296 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:39:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | scanf("%d%d",&m,&n); | ~~~~~^~~~~~~~~~~~~~ main.cpp:40:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 40 | REP(i,n)scanf("%d",cup+i); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef vector<int> vi;typedef vector<ll> vl;typedef pair<int,int> pii;typedef pair<ll,ll> pll;typedef int _loop_int;#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)#define DEBUG(x) cout<<#x<<": "<<x<<endl#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl#define ALL(a) (a).begin(),(a).end()#define CHMIN(a,b) a=min((a),(b))#define CHMAX(a,b) a=max((a),(b))// modconst ll MOD = 1000000007ll;#define FIX(a) ((a)%MOD+MOD)%MOD// floatingtypedef double Real;const Real EPS = 1e-11;#define EQ0(x) (abs(x)<EPS)#define EQ(a,b) (abs(a-b)<EPS)typedef complex<Real> P;int m;int n;int cup[25];int main(){scanf("%d%d",&m,&n);REP(i,n)scanf("%d",cup+i);sort(cup,cup+n);reverse(cup,cup+n);// eratosthenesvector<bool> sieve(m+10,true);sieve[0] = sieve[1] = false;REP(i,m+10){if(!sieve[i])continue;int it = 2*i;while(it<m+10){sieve[it] = false;it += i;}}// napsackvi mxcnt(m+1,-830252521);mxcnt[0] = 0;REP(i,n){int c = cup[i];REP(j,m+1){if(j+c>m)break;CHMAX(mxcnt[j+c],mxcnt[j]+1);}}// answerint ans = 0;REP(i,m+1){if(!sieve[i])continue;// i is prime// m-x == i causes chance// x = m-iif(mxcnt[m-i]>0){ans += mxcnt[m-i];}}int mx = 0;REP(i,m+1)CHMAX(mx,mxcnt[i]);ans += mx;printf("%d\n",ans);return 0;}