結果
問題 | No.1043 直列大学 |
ユーザー |
![]() |
提出日時 | 2020-05-01 22:26:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 2,137 bytes |
コンパイル時間 | 697 ms |
コンパイル使用メモリ | 86,316 KB |
実行使用メモリ | 160,976 KB |
最終ジャッジ日時 | 2024-12-22 19:34:43 |
合計ジャッジ時間 | 3,155 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include<iostream>#include<iomanip>#include<cmath>#include<string>#include<vector>#include<algorithm>#include<map>#include<set>#include<queue>#include<stack>using namespace std;typedef long long ll;#define fi first#define se second#define mp make_pairconst int inf=1e9+7;const ll mod=1e9+7;ll VDP[105][100005];ll RDP[105][100005];int main() {int N, M;cin>>N>>M;vector<ll> 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 A, B;cin>>A>>B;VDP[0][V[0]] = 1;RDP[0][R[0]] = 1;for(int i=1;i<N;++i){for(int j=1;j<=100000;++j){if(V[i]<=j){if(V[i]==j){VDP[i][j] = VDP[i-1][j] + 1;}else{VDP[i][j] = VDP[i-1][j] + VDP[i-1][j-V[i]];}}else{VDP[i][j] = VDP[i-1][j];}VDP[i][j] %= mod;}}for(int i=1;i<M;++i){for(int j=1;j<=100000;++j){if(R[i]<=j){if(R[i]==j){RDP[i][j] = RDP[i-1][j] + 1;}else{RDP[i][j] = RDP[i-1][j] + RDP[i-1][j-R[i]];}}else{RDP[i][j] = RDP[i-1][j];}RDP[i][j] %= mod;}}for(int i=1;i<100003;++i){VDP[N-1][i] += VDP[N-1][i-1];VDP[N-1][i] %= mod;//RDP[i] += RDP[i-1];}/**for(int i=0;i<N;++i){for(int j=0;j<100;++j){cout<<VDP[i][j]<<" ";}cout<<endl;}cout<<endl;**/ll ans = 0;for(ll i=1;i<=100000;++i){if(i*A>100000) break;if(i*B>100000){ans += ((VDP[N-1][100000] - VDP[N-1][i*A-1]) * RDP[M-1][i]) % mod;ans %= mod;}else{ans += ((VDP[N-1][i*B] - VDP[N-1][i*A-1]) * RDP[M-1][i]) % mod;ans %= mod;}}if(ans<0) cout<<ans + mod<<endl;else cout<<ans<<endl;}