結果

問題 No.247 線形計画問題もどき
ユーザー goodbatongoodbaton
提出日時 2015-07-17 23:39:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,340 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 72,232 KB
実行使用メモリ 83,512 KB
最終ジャッジ日時 2023-09-21 17:24:10
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
57,640 KB
testcase_01 AC 4 ms
8,512 KB
testcase_02 AC 80 ms
83,268 KB
testcase_03 AC 4 ms
8,524 KB
testcase_04 AC 4 ms
8,528 KB
testcase_05 AC 4 ms
8,648 KB
testcase_06 AC 3 ms
6,000 KB
testcase_07 AC 6 ms
8,556 KB
testcase_08 AC 3 ms
6,168 KB
testcase_09 AC 3 ms
6,192 KB
testcase_10 AC 4 ms
5,972 KB
testcase_11 AC 5 ms
10,532 KB
testcase_12 AC 5 ms
10,604 KB
testcase_13 AC 3 ms
8,712 KB
testcase_14 AC 5 ms
14,640 KB
testcase_15 AC 4 ms
8,496 KB
testcase_16 AC 4 ms
8,496 KB
testcase_17 AC 32 ms
53,580 KB
testcase_18 AC 7 ms
14,636 KB
testcase_19 AC 63 ms
83,360 KB
testcase_20 AC 74 ms
83,300 KB
testcase_21 AC 38 ms
83,308 KB
testcase_22 AC 43 ms
83,512 KB
testcase_23 AC 35 ms
74,032 KB
testcase_24 AC 69 ms
71,916 KB
testcase_25 AC 62 ms
78,060 KB
testcase_26 AC 14 ms
22,768 KB
testcase_27 AC 23 ms
41,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:21: warning: iteration 100001 invokes undefined behavior [-Waggressive-loop-optimizations]
             dp[i][j]=INF;
                     ^
main.cpp:40:22: note: within this loop
         for(int j=0;j<=SIZE;j++){
                      ^

ソースコード

diff #

#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 100001

ll 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;
}
0