# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
49885 |
2018-06-04T08:57:14 Z |
hamzqq9 |
Boat (APIO16_boat) |
C++14 |
|
1221 ms |
3132 KB |
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define cc pair<char,char>
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 100000000
#define M 10000002
#define N 550
#define LOG 20
#define magic 100
#define KOK 250
#define EPS 0.0025
#define pw(x) ((1ll)<<(x))
#define PI 3.1415926535
using namespace std;
int n,cev;
int a[N],b[N],dp[N][N],invf[N],f[N],val[N][N];
vector<ii> seg,e;
int add(int x,int y) {
x+=y;
while(x<0) x+=MOD;
while(x>=MOD) x-=MOD;
return x;
}
int mul(int x,int y) {
return 1ll*x*y%MOD;
}
int fe(int x,int y) {
if(y==0) return 1;
if(y==1) return x;
int res=fe(x,y/2);
res=mul(res,res);
if(y&1) res=mul(res,x);
return res;
}
int main() {
#if 0
freopen("input.txt","r",stdin);
#endif
f[0]=1;
invf[0]=1;
for(int i=1;i<N;i++) {
f[i]=mul(f[i-1],i);
invf[i]=fe(f[i],MOD-2);
}
for(int i=0;i<N;i++) {
for(int j=0;j<N;j++) {
for(int k=0;k<=min(i,j-1);k++) {
val[i][j]=add(val[i][j],mul(mul(f[i],f[j]),mul(mul(invf[k],invf[k+1]),mul(invf[i-k],invf[j-k-1]))));
}
}
}
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d %d",&a[i],&b[i]);
e.pb({a[i],0});
e.pb({b[i],1});
}
sort(all(e));
seg.pb({-inf,e[0].st-1});
for(int i=0;i<sz(e)-1;i++) {
int x=e[i].st+e[i].nd,y=e[i+1].st-!e[i+1].nd;
if(x>y) continue ;
seg.pb({x,y});
}
seg.pb({e.back().st+1,inf});
//for(auto ss:seg) printf("%d %d\n",ss.st,ss.nd);
for(int i=0;i<sz(seg);i++) dp[0][i]=1;
for(int i=1;i<=n;i++) {
int flag=0;
for(int now=0;now<sz(seg);now++) {
ii rng=seg[now];
if(rng.st>b[i] || rng.nd<a[i]) {
if(now) {
dp[i][now]=dp[i][now-1];
}
continue ;
}
int tot=0;
int sz=rng.nd-rng.st+1;
int ans=0;
for(int j=i-1;j>=0;j--) {
ans=add(ans,mul(val[tot][sz],dp[j][now-1]));
if(rng.st>=a[j] && rng.nd<=b[j]) {
tot++;
}
}
cev=add(cev,ans);
dp[i][now]=add(dp[i][now-1],ans);
//printf("RESULT : %d %d %d\n",i,now,ans);
}
}
printf("%d",cev);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:143:7: warning: unused variable 'flag' [-Wunused-variable]
int flag=0;
^~~~
boat.cpp:110:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
boat.cpp:114:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1221 ms |
2624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1221 ms |
2624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1065 ms |
3132 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1221 ms |
2624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |