結果

問題 No.247 線形計画問題もどき
ユーザー goodbatongoodbaton
提出日時 2015-07-17 23:38:23
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,340 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 72,324 KB
実行使用メモリ 82,360 KB
最終ジャッジ日時 2023-09-22 18:24:37
合計ジャッジ時間 3,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
57,604 KB
testcase_01 AC 5 ms
8,464 KB
testcase_02 RE -
testcase_03 AC 5 ms
8,736 KB
testcase_04 AC 5 ms
8,524 KB
testcase_05 AC 5 ms
8,504 KB
testcase_06 AC 4 ms
6,152 KB
testcase_07 AC 6 ms
8,464 KB
testcase_08 AC 4 ms
5,932 KB
testcase_09 AC 4 ms
6,004 KB
testcase_10 AC 4 ms
6,100 KB
testcase_11 AC 6 ms
10,556 KB
testcase_12 AC 5 ms
10,532 KB
testcase_13 AC 5 ms
8,532 KB
testcase_14 AC 7 ms
14,880 KB
testcase_15 AC 5 ms
8,504 KB
testcase_16 AC 5 ms
8,440 KB
testcase_17 AC 34 ms
53,500 KB
testcase_18 AC 8 ms
14,588 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 36 ms
74,104 KB
testcase_24 AC 71 ms
71,880 KB
testcase_25 AC 62 ms
78,076 KB
testcase_26 AC 15 ms
22,836 KB
testcase_27 AC 26 ms
41,232 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[100][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