結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2015-07-17 23:39:07 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 1,340 bytes |
コンパイル時間 | 592 ms |
コンパイル使用メモリ | 73,224 KB |
実行使用メモリ | 83,456 KB |
最終ジャッジ日時 | 2024-07-07 11:02:47 |
合計ジャッジ時間 | 2,144 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d%d",&c,&n); | ~~~~~^~~~~~~~~~~~~~ main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:41:21: warning: iteration 100001 invokes undefined behavior [-Waggressive-loop-optimizations] 41 | dp[i][j]=INF; | ^ main.cpp:40:22: note: within this loop 40 | for(int j=0;j<=SIZE;j++){ | ^
ソースコード
#include <cstdio>#include <cstdlib>#include <iostream>#include <string>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <cstring>typedef long long ll;using namespace std;#define mod 1000000007#define INF 1000000000#define LLINF 2000000000000000000LL#define MAX_L 5000000#define SIZE 100001ll dp[101][100001];int main(){int c,n;int a[100];bool m[SIZE];ll m_min[SIZE]={0};scanf("%d%d",&c,&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);for(int i=0;i<=n;i++){for(int j=0;j<=SIZE;j++){dp[i][j]=INF;}}dp[0][0]=0;for(int i=0;i<n;i++){for(int j=0;j<SIZE;j++){m[j]=false;m_min[j]=INF;}for(int j=0;j<=c;j++){if(m[j%a[i]]){m_min[j%a[i]]++;}if(dp[i][j]!=INF){m[j%a[i]]=true;m_min[j%a[i]]=min(m_min[j%a[i]],dp[i][j]);}if(m[j%a[i]]==true){dp[i+1][j]=m_min[j%a[i]];}}}if(dp[n][c]==INF) dp[n][c]=-1;printf("%lld\n",dp[n][c]);return 0;}