# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
63172 |
2018-08-01T03:54:03 Z |
qkxwsm |
Boat (APIO16_boat) |
C++17 |
|
1160 ms |
6360 KB |
/*
PROG: source
LANG: C++11
_____
.' '.
/ 0 0 \
| ^ |
| \ / |
\ '---' /
'._____.'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
struct chash
{
int operator()(int x) const
{
x ^= (x >> 20) ^ (x >> 12);
return x ^ (x >> 7) ^ (x >> 4);
}
int operator()(long long x) const
{
return x ^ (x >> 32);
}
};
template<typename T> using orderedset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename U> using hashtable = gp_hash_table<T, U, chash>;
template<class T>
void readi(T &x)
{
T input = 0;
bool negative = false;
char c = ' ';
while (c < '-')
{
c = getchar();
}
if (c == '-')
{
negative = true;
c = getchar();
}
while (c >= '0')
{
input = input * 10 + (c - '0');
c = getchar();
}
if (negative)
{
input = -input;
}
x = input;
}
template<class T>
void printi(T output)
{
if (output == 0)
{
putchar('0');
return;
}
if (output < 0)
{
putchar('-');
output = -output;
}
int aout[20];
int ilen = 0;
while(output)
{
aout[ilen] = ((output % 10));
output /= 10;
ilen++;
}
for (int i = ilen - 1; i >= 0; i--)
{
putchar(aout[i] + '0');
}
return;
}
template<class T>
void ckmin(T &a, T b)
{
a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
a = max(a, b);
}
template<class T, class U>
T normalize(T x, U mod = 1000000007)
{
return (((x % mod) + mod) % mod);
}
long long randomizell(long long mod)
{
return ((1ll << 45) * rand() + (1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}
int randomize(int mod)
{
return ((1ll << 15) * rand() + rand()) % mod;
}
#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << x << endl;
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-10;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 513
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
int N;
pii arr[MAXN];
vector<int> compress;
ll dp[MAXN][2 * MAXN], pref[MAXN][2 * MAXN];
ll modinv[MAXN], ifact[MAXN];
ll ans;
ll getpow(ll a, ll e)
{
if (e == 1)
{
return a;
}
ll was = getpow(a, e / 2);
if (e & 1)
{
return was * was % INF * a % INF;
}
return was * was % INF;
}
int getidx(int v)
{
return UB(compress.begin(), compress.end(), v) - compress.begin() - 1;
}
ll choose(int n, int k)
{
ll res = 1;
for (int i = 0; i < k; i++)
{
res *= (n - i);
res %= INF;
}
res *= ifact[k];
res %= INF;
return res;
}
ll f(ll m, ll k)
{
//put m guys into k slots
ll res = 0;
for (int i = 0; i <= m; i++)
{
res += choose(m, i) * choose(k + i - 1, i);
res %= INF;
}
// cerr << "fit " << m << " into " << k << ' ' << res << endl;
return res;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
srand(time(0));
// cout << fixed << setprecision(10);
// cerr << fixed << setprecision(10);
if (fopen("input.in", "r"))
{
freopen ("input.in", "r", stdin);
freopen ("output.out", "w", stdout);
}
cin >> N;
ifact[0] = 1; ifact[1] = 1; modinv[1] = 1;
for (int i = 2; i <= N; i++)
{
modinv[i] = getpow(i, INF - 2);
ifact[i] = ifact[i - 1] * modinv[i];
}
for (int i = 0; i < N; i++)
{
cin >> arr[i].fi >> arr[i].se;
arr[i].fi -= i;
arr[i].se -= i;
arr[i].se++;
compress.PB(arr[i].fi);
compress.PB(arr[i].se);
}
compress.PB(0);
sort(compress.begin(), compress.end());
compress.erase(unique(compress.begin(), compress.end()), compress.end());
//(1, 3); (1, 3)
//dp[i][j] stores
dp[0][0] = 1;
for (int i = 0; i < compress.size() - 1; i++)
{
pref[0][i] = 1;
}
for (int k = 1; k < compress.size() - 1; k++)
{
for (int i = 1; i <= N; i++)
{
for (int j = 0; j < i; j++)
{
//j...i - 1 are all in, and i - 1 MUST be active!
if (compress[k] < arr[i - 1].fi || compress[k] > arr[i - 1].se)
{
continue;
}
ll net = pref[j][k - 1];
int oks = 0;
for (int m = j; m < i; m++)
{
if (arr[m].fi <= compress[k] && compress[k] < arr[m].se)
{
oks++;
}
}
// cerr << "inside " << compress[k] << " oks " << oks << endl;
int spots = compress[k + 1] - compress[k];
ll fits = normalize(f(oks, spots) - f(oks - 1, spots), INF);
// dp[i][k] += net * choose(spots + oks - 1, oks);
// dp[i][k] %= INF;
// cerr << "oks " << oks << " spots " << spots << endl;
// cerr << "good ways to fit " << j << " to " << i - 1 << " in " << k << " is " << fits << endl;
dp[i][k] += net * fits;
dp[i][k] %= INF;
}
// cerr << "pos " << i - 1 << " finish " << k << ' ' << dp[i][k] << endl;
pref[i][k] = pref[i][k - 1] + dp[i][k];
pref[i][k] %= INF;
}
}
for (int i = 1; i <= N; i++)
{
for (int j = 1; j < compress.size() - 1; j++)
{
ans += dp[i][j];
ans %= INF;
}
}
cout << ans << '\n';
// cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" << endl;
return 0;
}
Compilation message
boat.cpp: In function 'int32_t main()':
boat.cpp:225:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < compress.size() - 1; i++)
~~^~~~~~~~~~~~~~~~~~~~~
boat.cpp:229:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 1; k < compress.size() - 1; k++)
~~^~~~~~~~~~~~~~~~~~~~~
boat.cpp:266:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 1; j < compress.size() - 1; j++)
~~^~~~~~~~~~~~~~~~~~~~~
boat.cpp:200:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen ("input.in", "r", stdin);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:201:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen ("output.out", "w", stdout);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
231 ms |
6360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
231 ms |
6360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1160 ms |
6360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
231 ms |
6360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |