# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
43325 |
2018-03-13T14:56:47 Z |
nonocut |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
748 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
const int maxn = 2e3 + 5;
const ll mod = 1e9 + 7;
int n;
int a[maxn], b[maxn];
vector<int> pos;
int sz;
pii itv[maxn];
ll dp[maxn], temp[maxn];
ll add(ll x, ll y) {
return ((x+y)%mod + mod)%mod;
}
ll mul(ll x, ll y) {
return ((x*y)%mod + mod)%mod;
}
ll inv(ll a, ll b){
return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void show(int key) {
// printf("show %d\n",key);
// for(int i=1;i<=sz;i++) printf("---- [%d, %d] : %lld\n",itv[i].X,itv[i].Y,dp[i]);
}
void init() {
pos.pb(0); pos.pb(2e9);
for(int i=1;i<=n;i++) pos.pb(a[i]), pos.pb(b[i]);
sort(pos.begin(),pos.end());
pos.erase(unique(pos.begin(),pos.end()),pos.end());
for(int i=0;i<pos.size()-1;i++) {
itv[++sz] = {pos[i],pos[i]};
if(pos[i]+1<=pos[i+1]-1) itv[++sz] = {pos[i]+1,pos[i+1]-1};
}
show(0);
}
ll solve() {
dp[1] = 1;
for(int cur=1;cur<=n;cur++) {
for(int x=1;x<=sz;x++) {
temp[x] = 0;
if(a[cur]<=itv[x].X && itv[x].Y<=b[cur]) {
int len = itv[x].Y-itv[x].X+1;
for(int y=1;y<x;y++) temp[x] = add(temp[x], mul(len, dp[y]));
temp[x] = add(temp[x], (mul(mul(len-1, inv(2,mod)), dp[x])));
}
}
for(int x=1;x<=sz;x++) dp[x] = add(dp[x], temp[x]);
show(cur);
}
ll ans = 0;
for(int x=2;x<=sz;x++) ans = add(ans, dp[x]);
return ans;
}
ll solve2() {
ll ans = 0;
for(int i=1;i<=n;i++) {
dp[i] = 1;
for(int j=1;j<i;j++) {
if(a[i]>a[j]) dp[i] = add(dp[i], dp[j]);
}
ans = add(ans, dp[i]);
}
return ans;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
init();
printf("%lld",solve());
}
Compilation message
boat.cpp: In function 'void init()':
boat.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<pos.size()-1;i++) {
^
boat.cpp: In function 'int main()':
boat.cpp:79:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
boat.cpp:80:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
424 KB |
Output is correct |
4 |
Correct |
7 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
476 KB |
Output is correct |
6 |
Correct |
7 ms |
476 KB |
Output is correct |
7 |
Correct |
7 ms |
528 KB |
Output is correct |
8 |
Correct |
7 ms |
532 KB |
Output is correct |
9 |
Correct |
7 ms |
580 KB |
Output is correct |
10 |
Correct |
9 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
604 KB |
Output is correct |
12 |
Correct |
8 ms |
732 KB |
Output is correct |
13 |
Correct |
7 ms |
732 KB |
Output is correct |
14 |
Correct |
7 ms |
732 KB |
Output is correct |
15 |
Correct |
7 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
3 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
3 ms |
732 KB |
Output is correct |
20 |
Correct |
3 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
424 KB |
Output is correct |
4 |
Correct |
7 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
476 KB |
Output is correct |
6 |
Correct |
7 ms |
476 KB |
Output is correct |
7 |
Correct |
7 ms |
528 KB |
Output is correct |
8 |
Correct |
7 ms |
532 KB |
Output is correct |
9 |
Correct |
7 ms |
580 KB |
Output is correct |
10 |
Correct |
9 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
604 KB |
Output is correct |
12 |
Correct |
8 ms |
732 KB |
Output is correct |
13 |
Correct |
7 ms |
732 KB |
Output is correct |
14 |
Correct |
7 ms |
732 KB |
Output is correct |
15 |
Correct |
7 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
3 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
3 ms |
732 KB |
Output is correct |
20 |
Correct |
3 ms |
732 KB |
Output is correct |
21 |
Execution timed out |
2052 ms |
732 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
424 KB |
Output is correct |
4 |
Correct |
7 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
476 KB |
Output is correct |
6 |
Correct |
7 ms |
476 KB |
Output is correct |
7 |
Correct |
7 ms |
528 KB |
Output is correct |
8 |
Correct |
7 ms |
532 KB |
Output is correct |
9 |
Correct |
7 ms |
580 KB |
Output is correct |
10 |
Correct |
9 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
604 KB |
Output is correct |
12 |
Correct |
8 ms |
732 KB |
Output is correct |
13 |
Correct |
7 ms |
732 KB |
Output is correct |
14 |
Correct |
7 ms |
732 KB |
Output is correct |
15 |
Correct |
7 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
3 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
3 ms |
732 KB |
Output is correct |
20 |
Correct |
3 ms |
732 KB |
Output is correct |
21 |
Execution timed out |
2052 ms |
732 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |