結果

問題 No.1043 直列大学
ユーザー akun0716
提出日時 2020-05-01 23:03:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,209 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 88,940 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-12-22 19:38:01
合計ジャッジ時間 3,153 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M; cin >> N >> M;
VI V(N), R(M);
REP(i, N)cin >> V[i];
REP(i, M)cin >> R[i];
int A, B; cin >> A >> B;
SORT(V);
SORT(R);
int dp1[2][100010] = { 0 }, dp2[2][100010] = { 0 };
dp1[0][0] = dp2[0][0] = 1;
REP(i, N) {
REP(j, 100010) {
dp1[(i + 1) % 2][j] += dp1[i % 2][j];
if (j + V[i] < 100010) {
dp1[(i + 1) % 2][j + V[i]] += dp1[i % 2][j];
}
}
REP(j, 100010) {
dp1[i % 2][j] = 0;
dp1[(i + 1) % 2][j] %= mod;
}
}
REP(i, M) {
REP(j, 100010) {
dp2[(i + 1) % 2][j] += dp2[i % 2][j];
if (j + R[i] < 100010) {
dp2[(i + 1) % 2][j + R[i]] += dp2[i % 2][j];
}
}
REP(j, 100010) {
dp2[i % 2][j] = 0;
dp2[(i + 1) % 2][j] %= mod;
}
}
int ans = 0;
int cnt[100010] = { 0 };
FOR(i, 1, 100010) {
cnt[i] = cnt[i - 1] + dp1[N % 2][i];
cnt[i] %= mod;
}
eFOR(i, 1, 100000) {
int ma = B * i, mi = A * i;
mi--;
if (mi >= 100000) {
continue;
}
chmin(ma, 100000LL);
chmin(mi, 100000LL);
ans += (cnt[ma] - cnt[mi] + mod)*dp2[M % 2][i];
ans %= mod;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0