結果

問題 No.1043 直列大学
ユーザー saksak
提出日時 2020-08-19 12:43:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 1,935 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 204,680 KB
実行使用メモリ 161,308 KB
最終ジャッジ日時 2023-08-24 12:53:39
合計ジャッジ時間 6,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,548 KB
testcase_01 AC 2 ms
5,428 KB
testcase_02 AC 3 ms
6,136 KB
testcase_03 AC 2 ms
5,452 KB
testcase_04 AC 2 ms
5,436 KB
testcase_05 AC 2 ms
5,472 KB
testcase_06 AC 2 ms
5,608 KB
testcase_07 AC 2 ms
5,552 KB
testcase_08 AC 2 ms
5,616 KB
testcase_09 AC 61 ms
45,084 KB
testcase_10 AC 89 ms
63,136 KB
testcase_11 AC 196 ms
137,624 KB
testcase_12 AC 232 ms
161,308 KB
testcase_13 AC 167 ms
117,816 KB
testcase_14 AC 186 ms
129,188 KB
testcase_15 AC 217 ms
152,256 KB
testcase_16 AC 174 ms
122,160 KB
testcase_17 AC 96 ms
68,380 KB
testcase_18 AC 98 ms
69,824 KB
testcase_19 AC 162 ms
113,152 KB
testcase_20 AC 92 ms
65,864 KB
testcase_21 AC 140 ms
99,856 KB
testcase_22 AC 149 ms
104,700 KB
testcase_23 AC 229 ms
159,616 KB
testcase_24 AC 116 ms
81,900 KB
testcase_25 AC 158 ms
112,192 KB
testcase_26 AC 185 ms
129,528 KB
testcase_27 AC 51 ms
37,840 KB
testcase_28 AC 156 ms
110,292 KB
testcase_29 AC 19 ms
15,760 KB
testcase_30 AC 111 ms
79,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, M; cin >> N >> M;
  ll V[N]; rep(i,N) cin >> V[i];
  ll R[M]; rep(i,M) cin >> R[i];
  ll A, B; cin >> A >> B;

  // ll dpv[N+1][1000*N+1] = {}; dpv[0][0] = 1;
  static ll dpv[100+1][1000*100+1] = {}; dpv[0][0] = 1;
  rep(i,N) rep(j,1000*N+1) {
    dpv[i+1][j] = (dpv[i+1][j] + dpv[i][j]) % MOD;
    if (V[i]+j<=1000*N) dpv[i+1][V[i]+j] = (dpv[i+1][V[i]+j] + dpv[i][j]) % MOD;
  }

  // ll dpr[M+1][1000*M+1] = {}; dpr[0][0] = 1;
  static ll dpr[100+1][1000*100+1] = {}; dpr[0][0] = 1;
  rep(i,M) rep(j,1000*M+1) {
    dpr[i+1][j] = (dpr[i+1][j] + dpr[i][j]) % MOD;
    if (R[i]+j<=1000*M) dpr[i+1][R[i]+j] = (dpr[i+1][R[i]+j] + dpr[i][j]) % MOD;
  }

  ll sv[1000*N+1] = {}; rep(i,1000*N+1) sv[i] = i==0 ? dpv[N][i] : (sv[i-1]+dpv[N][i]) % MOD;
  // debug(sv,sv+20);

  ll result = 0;
  repr(i,1,1000*M+1) {
    if (i*A>1000*N) break;
    ll l = i*A-1, r = min(i*B, 1000*N);
    result = ( result + (sv[r]-sv[l]+MOD)*dpr[M][i] ) % MOD;
  }
  cout << result << endl;
  return 0;
}
0