Contest Duration: - (local time) (100 minutes) Back to Home

Submission #3511697

Source Code Expand

Copy
```#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

template<unsigned MOD>  class ModInt {
public:
ModInt(): x(0) {}
ModInt(signed y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}
ModInt(signed long long y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}

// Arithmetic Oprators
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD) x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD) x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = 1LL * x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) {
return *this *= ModInt(get<1>(extgcd(that.x, int(MOD))));
}
ModInt &operator%=(ModInt that) {
x %= that.x;
return *this;
}

ModInt &operator+=(const int that) { return *this += ModInt(that);}
ModInt &operator-=(const int that) { return *this -= ModInt(that);}
ModInt &operator*=(const int that) { return *this *= ModInt(that);}
ModInt &operator/=(const int that) { return *this /= ModInt(that);}
ModInt &operator%=(const int that) { return *this %= ModInt(that);}

// Comparators
bool operator <(ModInt that) { return x < that.x; }
bool operator >(ModInt that) { return x > that.x; }
bool operator<=(ModInt that) { return x <= that.x; }
bool operator>=(ModInt that) { return x >= that.x; }
bool operator!=(ModInt that) { return x != that.x; }
bool operator==(ModInt that) { return x == that.x; }

// Utilities
unsigned getval() const { return x;}
ModInt operator+(ModInt that) const { return ModInt(*this) += that;}
ModInt operator-(ModInt that) const { return ModInt(*this) -= that;}
ModInt operator*(ModInt that) const { return ModInt(*this) *= that;}
ModInt operator/(ModInt that) const { return ModInt(*this) /= that;}
ModInt operator%(ModInt that) const { return ModInt(*this) %= that;}
ModInt operator+(const int that) const { return ModInt(*this) += that;}
ModInt operator-(const int that) const { return ModInt(*this) -= that;}
ModInt operator*(const int that) const { return ModInt(*this) *= that;}
ModInt operator/(const int that) const { return ModInt(*this) /= that;}
ModInt operator%(const int that) const { return ModInt(*this) %= that;}
ModInt operator=(const int that) { return *this = ModInt(that);}
friend istream &operator>>(istream& is, ModInt &that) {ll tmp; is >> tmp; that = ModInt(tmp);return is;}
friend ostream &operator<<(ostream& os, const ModInt &that) { return os << that.x; }

ModInt power(ll n) const {
ll b = 1LL, a = x;
while(n){
if(n & 1) b = b * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return ModInt(b);
}
private:
unsigned x;

inline auto extgcd(int a, int b) {
if (b == 0) return make_tuple(a, 1, 0);
tuple<int, int, int> ret = extgcd(b, a % b);
swap(get<1>(ret), get<2>(ret));
get<2>(ret) -= a / b * get<1>(ret);
return ret;
}
};

const int mod = 1000000007;
using mint = ModInt<mod>;
const mint ZERO = mint(0);
const mint ONE = mint(1);

const int limit = 400;
mint dp[410][410];
mint memo[410][410];

int main(void){
int n,c;
cin >> n >> c;

vector<int> a(n),b(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];

rep(k,limit+1)rep(i,1,limit+1){
memo[k][i] = memo[k][i-1];
memo[k][i] += mint(i).power(k);
}

dp[0][0] = ONE;
rep(i,n)rep(j,c+1){
if(dp[i][j] == ZERO) continue;
rep(k,c-j+1){
mint cur = dp[i][j] * (memo[k][b[i]] - memo[k][a[i] -1]);
dp[i + 1][j + k] += cur;
}
}

cout << dp[n][c] << endl;
return 0;
}```

Submission Info

Submission Time 2018-11-01 02:03:53+0900 E - Children and Candies Hec C++14 (GCC 5.4.1) 800 4766 Byte AC 369 ms 1536 KB

Judge Result

Score / Max Score 0 / 0 400 / 400 400 / 400
Status
 AC × 5
 AC × 12
 AC × 30
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt
Subtask 0_001, 0_003, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 2_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt
Case Name Status Exec Time Memory
0_000.txt AC 8 ms 1536 KB
0_001.txt AC 8 ms 1536 KB
0_002.txt AC 8 ms 1536 KB
0_003.txt AC 8 ms 1536 KB
0_004.txt AC 8 ms 1536 KB
1_005.txt AC 8 ms 1536 KB
1_006.txt AC 8 ms 1536 KB
1_007.txt AC 8 ms 1536 KB
1_008.txt AC 8 ms 1536 KB
1_009.txt AC 8 ms 1536 KB
1_010.txt AC 8 ms 1536 KB
1_011.txt AC 8 ms 1536 KB
1_012.txt AC 8 ms 1536 KB
1_013.txt AC 8 ms 1536 KB
1_014.txt AC 173 ms 1536 KB
1_015.txt AC 368 ms 1536 KB
1_016.txt AC 365 ms 1536 KB
2_017.txt AC 8 ms 1536 KB
2_018.txt AC 8 ms 1536 KB
2_019.txt AC 8 ms 1536 KB
2_020.txt AC 8 ms 1536 KB
2_021.txt AC 8 ms 1536 KB
2_022.txt AC 8 ms 1536 KB
2_023.txt AC 368 ms 1536 KB
2_024.txt AC 369 ms 1536 KB
2_025.txt AC 64 ms 1536 KB
2_026.txt AC 9 ms 1536 KB
2_027.txt AC 299 ms 1536 KB
2_028.txt AC 13 ms 1536 KB
2_029.txt AC 10 ms 1536 KB