Submission #554275

# Submission time Handle Problem Language Result Execution time Memory
554275 2022-04-28T06:01:03 Z Koosha_mv Boat (APIO16_boat) C++14
0 / 100
2000 ms 32508 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll

const int N=1005,mod=1e9+7;

int n,m,s[N],e[N],dp[N][N],ifac[N],C[N][N];
vector<int> A;

ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}

int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ifac[0]=1;
	f(i,1,N) ifac[i]=1ll*ifac[i-1]*pow(i,mod-2,mod)%mod;
	cin>>n;
	f(i,1,n+1){
		cin>>s[i]>>e[i],e[i]++;
		A.pb(s[i]);
		A.pb(e[i]);
	}
	sort(all(A));
	A.resize(unique(A.begin(),A.end())-A.begin());
	m=A.size();
	f(i,0,A.size()-1){
		C[i][0]=1;
		f(j,1,A[i+1]-A[i]+1){
			C[i][j]=C[i][j-1]*pow(j,mod-2,mod)%mod*(A[i+1]-A[i]+1-j)%mod;
		}
	}
	f(i,1,n+1){
		f(j,0,m-1) dp[j][0]=0;
		dp[0][0]=1;
		f(j,0,m-1){
			Add(dp[j+1][0],dp[j][0]);
			f(k,1,i+1) Add(dp[j+1][0],dp[j][k]*C[j][k]%mod);
		}
		f(j,0,m-1){
			if(e[i]<=A[j] || A[j+1]<=s[i]) continue ;
			f_(k,i,1){
				Add(dp[j][k],dp[j][k-1]);
			}
		}
	}
	int ans=0;
	f(i,0,m-1){
		f(j,1,n+1){
			Add(ans,dp[i][j]*C[i][j]%mod);
		}
	}
	cout<<ans;
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   44 |  f(i,0,A.size()-1){
      |    ~~~~~~~~~~~~~~              
boat.cpp:44:2: note: in expansion of macro 'f'
   44 |  f(i,0,A.size()-1){
      |  ^
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 14184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 14184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 785 ms 32508 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 14184 KB Time limit exceeded
2 Halted 0 ms 0 KB -