# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
80749 |
2018-10-22T08:07:04 Z |
polyfish |
Boat (APIO16_boat) |
C++14 |
|
101 ms |
11636 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 502;
const int MOD = 1000000007;
int n;
int64_t f[MAX_N][MAX_N*2], ps[MAX_N][MAX_N*2], C[2*MAX_N][MAX_N], fact[MAX_N];
pair<int, int> s[MAX_N];
vector<pair<int, int> > t;
void enter() {
cin >> n;
for (int i=1; i<=n; ++i) {
cin >> s[i].first >> s[i].second;
}
}
int64_t pw(int64_t n, int k) {
if (k==0)
return 1;
int64_t tmp = pw(n, k/2);
if (k%2)
return tmp * tmp % MOD * n % MOD;
return tmp * tmp % MOD;
}
void init() {
vector<int> b;
for (int i=1; i<=n; ++i) {
b.push_back(s[i].first);
b.push_back(s[i].second+1);
}
sort(b.begin(), b.end());
t.push_back(make_pair(0, 0));
t.push_back(make_pair(0, 0));
for (int i=0; i+1<b.size(); ++i) {
if (b[i+1]-1>=b[i])
t.push_back(make_pair(b[i], b[i+1]-1));
}
sort(t.begin(), t.end());
fact[0] = 1;
for (int i=1; i<=n; ++i)
fact[i] = fact[i-1] * i % MOD;
for (int i=1; i<t.size(); ++i) {
int len = t[i].second - t[i].first + 1;
int64_t tmp = 1;
for (int k=1; k<=min(len, n); ++k) {
tmp = tmp * (len-k+1) % MOD;
C[i][k] = tmp * pw(fact[k], MOD-2) % MOD;
}
}
}
bool intersect(pair<int, int> p, pair<int, int> q) {
return !(p.second < q.first || p.first>q.second);
}
void solve() {
int64_t res = 0;
f[0][1] = 1;
for (int j=1; j<t.size(); ++j)
ps[0][j] = 1;
for (int i=1; i<=n; ++i) {
for (int j=1; j<t.size(); ++j) {
if (intersect(s[i], t[j])) {
for (int k=i; k>=1; --k) {
if (!intersect(t[j], s[k]))
break;
f[i][j] = (f[i][j] + ps[k-1][j-1] * C[j][i-k+1]) % MOD;
//cerr << ps[k-1][j-1] << ' ' << C[t[j].first-t[j].second+1][i-k+1] << '\n';
}
}
res = (res + f[i][j]) % MOD;
}
for (int j=1; j<t.size(); ++j)
ps[i][j] = (ps[i][j-1] + ps[i-1][j] - ps[i-1][j-1] + MOD + f[i][j]) % MOD;
}
cout << res;
}
int main() {
//freopen("boat.inp", "r", stdin);
//freopen("boat.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
enter();
init();
solve();
}
Compilation message
boat.cpp: In function 'void init()':
boat.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i+1<b.size(); ++i) {
~~~^~~~~~~~~
boat.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=1; i<t.size(); ++i) {
~^~~~~~~~~
boat.cpp: In function 'void solve()':
boat.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=1; j<t.size(); ++j)
~^~~~~~~~~
boat.cpp:65:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=1; j<t.size(); ++j) {
~^~~~~~~~~
boat.cpp:76:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=1; j<t.size(); ++j)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
10232 KB |
Output is correct |
2 |
Correct |
93 ms |
10420 KB |
Output is correct |
3 |
Correct |
100 ms |
10420 KB |
Output is correct |
4 |
Correct |
96 ms |
10432 KB |
Output is correct |
5 |
Correct |
95 ms |
10480 KB |
Output is correct |
6 |
Correct |
94 ms |
10824 KB |
Output is correct |
7 |
Correct |
93 ms |
10824 KB |
Output is correct |
8 |
Correct |
93 ms |
10824 KB |
Output is correct |
9 |
Correct |
94 ms |
10824 KB |
Output is correct |
10 |
Correct |
95 ms |
10852 KB |
Output is correct |
11 |
Correct |
94 ms |
10852 KB |
Output is correct |
12 |
Correct |
96 ms |
10852 KB |
Output is correct |
13 |
Correct |
93 ms |
10852 KB |
Output is correct |
14 |
Correct |
101 ms |
10912 KB |
Output is correct |
15 |
Correct |
93 ms |
10912 KB |
Output is correct |
16 |
Correct |
22 ms |
10912 KB |
Output is correct |
17 |
Correct |
24 ms |
10912 KB |
Output is correct |
18 |
Correct |
26 ms |
10912 KB |
Output is correct |
19 |
Correct |
24 ms |
10912 KB |
Output is correct |
20 |
Correct |
23 ms |
10912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
10232 KB |
Output is correct |
2 |
Correct |
93 ms |
10420 KB |
Output is correct |
3 |
Correct |
100 ms |
10420 KB |
Output is correct |
4 |
Correct |
96 ms |
10432 KB |
Output is correct |
5 |
Correct |
95 ms |
10480 KB |
Output is correct |
6 |
Correct |
94 ms |
10824 KB |
Output is correct |
7 |
Correct |
93 ms |
10824 KB |
Output is correct |
8 |
Correct |
93 ms |
10824 KB |
Output is correct |
9 |
Correct |
94 ms |
10824 KB |
Output is correct |
10 |
Correct |
95 ms |
10852 KB |
Output is correct |
11 |
Correct |
94 ms |
10852 KB |
Output is correct |
12 |
Correct |
96 ms |
10852 KB |
Output is correct |
13 |
Correct |
93 ms |
10852 KB |
Output is correct |
14 |
Correct |
101 ms |
10912 KB |
Output is correct |
15 |
Correct |
93 ms |
10912 KB |
Output is correct |
16 |
Correct |
22 ms |
10912 KB |
Output is correct |
17 |
Correct |
24 ms |
10912 KB |
Output is correct |
18 |
Correct |
26 ms |
10912 KB |
Output is correct |
19 |
Correct |
24 ms |
10912 KB |
Output is correct |
20 |
Correct |
23 ms |
10912 KB |
Output is correct |
21 |
Incorrect |
21 ms |
11636 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
11636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
10232 KB |
Output is correct |
2 |
Correct |
93 ms |
10420 KB |
Output is correct |
3 |
Correct |
100 ms |
10420 KB |
Output is correct |
4 |
Correct |
96 ms |
10432 KB |
Output is correct |
5 |
Correct |
95 ms |
10480 KB |
Output is correct |
6 |
Correct |
94 ms |
10824 KB |
Output is correct |
7 |
Correct |
93 ms |
10824 KB |
Output is correct |
8 |
Correct |
93 ms |
10824 KB |
Output is correct |
9 |
Correct |
94 ms |
10824 KB |
Output is correct |
10 |
Correct |
95 ms |
10852 KB |
Output is correct |
11 |
Correct |
94 ms |
10852 KB |
Output is correct |
12 |
Correct |
96 ms |
10852 KB |
Output is correct |
13 |
Correct |
93 ms |
10852 KB |
Output is correct |
14 |
Correct |
101 ms |
10912 KB |
Output is correct |
15 |
Correct |
93 ms |
10912 KB |
Output is correct |
16 |
Correct |
22 ms |
10912 KB |
Output is correct |
17 |
Correct |
24 ms |
10912 KB |
Output is correct |
18 |
Correct |
26 ms |
10912 KB |
Output is correct |
19 |
Correct |
24 ms |
10912 KB |
Output is correct |
20 |
Correct |
23 ms |
10912 KB |
Output is correct |
21 |
Incorrect |
21 ms |
11636 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |