結果

問題 No.1043 直列大学
ユーザー KKT89KKT89
提出日時 2020-05-01 22:07:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,366 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 95,116 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2023-08-26 13:55:56
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,580 KB
testcase_01 AC 7 ms
6,600 KB
testcase_02 AC 10 ms
6,600 KB
testcase_03 AC 7 ms
6,604 KB
testcase_04 AC 7 ms
6,600 KB
testcase_05 AC 7 ms
6,600 KB
testcase_06 AC 7 ms
6,604 KB
testcase_07 AC 8 ms
6,824 KB
testcase_08 AC 8 ms
6,692 KB
testcase_09 AC 37 ms
6,728 KB
testcase_10 AC 44 ms
6,656 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 33 ms
6,636 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:52:21: 警告: iteration 100099 invokes undefined behavior [-Waggressive-loop-optimizations]
   52 |         (dp[pre][i+1]+=dp[pre][i])%=mod;
      |          ~~~~~~~~~~~^
main.cpp:51:18: 備考: within this loop
   51 |     for(int i=0;i<100100;i++){
      |                 ~^~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <math.h>
using namespace std;

typedef long long ll;

constexpr ll mod=1e9+7;

ll dp[2][100100];
ll dp2[2][100101];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> v(n),r(m);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<m;i++){
        cin >> r[i];
    }
    int pre=0;
    int nex=1;
    dp[0][0]=1;
    int a,b; cin >> a >> b;
    for(int i=0;i<n;i++){
        for(int j=0;j<100000;j++){
            (dp[nex][j+v[i]]+=dp[pre][j])%=mod;
            (dp[nex][j]+=dp[pre][j])%=mod;
            dp[pre][j]=0;
        }
        swap(pre,nex);
    }
    int ppre=0;
    int nnex=1;
    dp2[0][0]=1;
    for(int i=0;i<m;i++){
        for(int j=0;j<100000;j++){
            (dp2[nnex][j+r[i]]+=dp2[ppre][j])%=mod;
            (dp2[nnex][j]+=dp2[ppre][j])%=mod;
            dp2[ppre][j]=0;
        }
        swap(nnex,ppre);
    }
    for(int i=0;i<100100;i++){
        (dp[pre][i+1]+=dp[pre][i])%=mod;
    }
    ll res=0;
    for(int i=1;i<100100;i++){
        if(dp2[ppre][i]==0)continue;
        ll aa=min((ll)a*i,100000LL);
        ll bb=min((ll)b*i,100000LL);
        (res+=(dp[pre][bb]-dp[pre][aa-1])%mod*dp2[ppre][i])%=mod;
    }
    printf("%lld\n",res);
}
0