# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
257962 |
2020-08-05T06:28:43 Z |
daniel920712 |
Boat (APIO16_boat) |
C++14 |
|
2000 ms |
4636 KB |
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <time.h>
using namespace std;
long long MOD=1e9+7;
map < pair < long long , long long > , long long > all;
long long N;
long long a[505],b[505];
map < long long , long long > con,r;
set < long long > have;
long long Pow(long long a,long long b)
{
if(b==0) return a;
long long t=Pow(a,b/2);
t*=t;
t%=MOD;
if(b%2) t*=a;
return t%MOD;
}
long long F(long long x,long long y)
{
long long i,j,now;
if(x==0) return y!=(1e9+5);
if(all.find(make_pair(x,y))!=all.end()) return all[make_pair(x,y)];
all[make_pair(x,y)]=F(x-1,y);
for(auto i:con)
{
if(i.first>=a[x]&&r[i.first]<y&&r[i.first]<=b[x])
{
now=1;
for(j=x;j>=1;j--)
{
if(i.first>=a[j]&&r[i.first]<y&&r[i.first]<=b[j])
{
now*=(i.second-(x-j));
now%=MOD;
now*=Pow(x-j+1,MOD-2);
now%=MOD;
all[make_pair(x,y)]+=now*F(j-1,i.first)%MOD;
all[make_pair(x,y)]%=MOD;
}
else break;
}
}
}
return all[make_pair(x,y)];
}
long long F2(long long x,long long y)
{
long long i;
//printf("%lld %lld\n",x,y);
if(x==0) return y!=1e9+5;
if(all.find(make_pair(x,y))!=all.end()) return all[make_pair(x,y)];
all[make_pair(x,y)]=F2(x-1,y);
for(i=a[x];i<=min(b[x],y-1);i++)
{
all[make_pair(x,y)]+=F2(x-1,i);
all[make_pair(x,y)]%=MOD;
}
return all[make_pair(x,y)];
}
int main()
{
//freopen("3_01.in","rt",stdin);
//srand(time(NULL));
long long N,M,i;
scanf("%lld",&N);
for(i=1;i<=N;i++)
{
scanf("%lld %lld",&a[i],&b[i]);
//b[i]=rand()%100;
//a[i]=rand()%100;
//if(a[i]>b[i]) swap(a[i],b[i]);
//printf("%lld %lld\n",a[i],b[i]);
have.insert(a[i]);
have.insert(a[i]+1);
have.insert(b[i]);
have.insert(b[i]+1);
}
for(auto i:have)
{
if(i==*prev(have.end()))
{
con[i]=1;
r[i]=i;
}
//printf("%lld %lld\n",*prev(have.lower_bound(i)),i);
if(have.lower_bound(i)!=have.begin())
{
con[*prev(have.lower_bound(i))]=i-*prev(have.lower_bound(i));
r[*prev(have.lower_bound(i))]=i-1;
}
}
printf("%lld\n",F(N,1e9+5));
return 0;
}
/*
2
32 47
18 78
*/
Compilation message
boat.cpp: In function 'long long int F(long long int, long long int)':
boat.cpp:26:15: warning: unused variable 'i' [-Wunused-variable]
long long i,j,now;
^
boat.cpp: In function 'int main()':
boat.cpp:76:17: warning: unused variable 'M' [-Wunused-variable]
long long N,M,i;
^
boat.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&N);
~~~~~^~~~~~~~~~~
boat.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2083 ms |
4636 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2083 ms |
4636 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2085 ms |
1900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2083 ms |
4636 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |