結果
| 問題 |
No.1043 直列大学
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-01 22:07:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,366 bytes |
| コンパイル時間 | 943 ms |
| コンパイル使用メモリ | 94,436 KB |
| 最終ジャッジ日時 | 2025-01-10 04:54:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 RE * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:52:21: warning: iteration 100099 invokes undefined behavior [-Waggressive-loop-optimizations]
52 | (dp[pre][i+1]+=dp[pre][i])%=mod;
| ~~~~~~~~~~~^
main.cpp:51:18: note: within this loop
51 | for(int i=0;i<100100;i++){
| ~^~~~~~~
ソースコード
#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);
}