# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
43324 |
2018-03-13T14:53:30 Z |
nonocut |
Boat (APIO16_boat) |
C++14 |
|
3 ms |
1008 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());
unique(pos.begin(),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",solve2());
}
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 |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
352 KB |
Output is correct |
3 |
Correct |
3 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
704 KB |
Output is correct |
6 |
Correct |
3 ms |
812 KB |
Output is correct |
7 |
Correct |
3 ms |
824 KB |
Output is correct |
8 |
Correct |
3 ms |
840 KB |
Output is correct |
9 |
Correct |
3 ms |
840 KB |
Output is correct |
10 |
Correct |
3 ms |
876 KB |
Output is correct |
11 |
Correct |
3 ms |
888 KB |
Output is correct |
12 |
Correct |
3 ms |
900 KB |
Output is correct |
13 |
Correct |
3 ms |
916 KB |
Output is correct |
14 |
Correct |
3 ms |
924 KB |
Output is correct |
15 |
Correct |
3 ms |
936 KB |
Output is correct |
16 |
Correct |
2 ms |
948 KB |
Output is correct |
17 |
Correct |
3 ms |
960 KB |
Output is correct |
18 |
Correct |
2 ms |
972 KB |
Output is correct |
19 |
Correct |
3 ms |
984 KB |
Output is correct |
20 |
Correct |
2 ms |
1000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
352 KB |
Output is correct |
3 |
Correct |
3 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
704 KB |
Output is correct |
6 |
Correct |
3 ms |
812 KB |
Output is correct |
7 |
Correct |
3 ms |
824 KB |
Output is correct |
8 |
Correct |
3 ms |
840 KB |
Output is correct |
9 |
Correct |
3 ms |
840 KB |
Output is correct |
10 |
Correct |
3 ms |
876 KB |
Output is correct |
11 |
Correct |
3 ms |
888 KB |
Output is correct |
12 |
Correct |
3 ms |
900 KB |
Output is correct |
13 |
Correct |
3 ms |
916 KB |
Output is correct |
14 |
Correct |
3 ms |
924 KB |
Output is correct |
15 |
Correct |
3 ms |
936 KB |
Output is correct |
16 |
Correct |
2 ms |
948 KB |
Output is correct |
17 |
Correct |
3 ms |
960 KB |
Output is correct |
18 |
Correct |
2 ms |
972 KB |
Output is correct |
19 |
Correct |
3 ms |
984 KB |
Output is correct |
20 |
Correct |
2 ms |
1000 KB |
Output is correct |
21 |
Incorrect |
3 ms |
1008 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
352 KB |
Output is correct |
3 |
Correct |
3 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
704 KB |
Output is correct |
6 |
Correct |
3 ms |
812 KB |
Output is correct |
7 |
Correct |
3 ms |
824 KB |
Output is correct |
8 |
Correct |
3 ms |
840 KB |
Output is correct |
9 |
Correct |
3 ms |
840 KB |
Output is correct |
10 |
Correct |
3 ms |
876 KB |
Output is correct |
11 |
Correct |
3 ms |
888 KB |
Output is correct |
12 |
Correct |
3 ms |
900 KB |
Output is correct |
13 |
Correct |
3 ms |
916 KB |
Output is correct |
14 |
Correct |
3 ms |
924 KB |
Output is correct |
15 |
Correct |
3 ms |
936 KB |
Output is correct |
16 |
Correct |
2 ms |
948 KB |
Output is correct |
17 |
Correct |
3 ms |
960 KB |
Output is correct |
18 |
Correct |
2 ms |
972 KB |
Output is correct |
19 |
Correct |
3 ms |
984 KB |
Output is correct |
20 |
Correct |
2 ms |
1000 KB |
Output is correct |
21 |
Incorrect |
3 ms |
1008 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |