답안 #724365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724365 2023-04-15T06:51:17 Z sunwukong123 Boat (APIO16_boat) C++14
27 / 100
2000 ms 1352 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(i,s,e) for(int i = s; i <= (int)e; ++i)
#define DEC(i,s,e) for(int i = s; i >= (int)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define reach 
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first 
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
typedef tuple<int,int,int,int> ti4;
int rand(int a, int b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (long long)1e18 + 500;
template <typename T> void chmax(T& a, const T b) { a=max(a,b); }
template <typename T> void chmin(T& a, const T b) { a=min(a,b); }
const int MAXN = 1005;
int n;
vector<int> points;
int L[MAXN],R[MAXN];
int dp[MAXN][MAXN]; // dp(i,c)=number of ways to reach the ith segment with c objects inside the ith segment
int S[MAXN];
int sz[MAXN];
int qexp(int a, int b, int mod) {
	a%=mod;
	int res = 1;
	while(b) {
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}

int choose(int n, int k) {
    int x = 1, y = 1;
    FOR(i,0,k-1) {
        y*=n-i;
        x*=k-i;
        y%=MOD;
        x%=MOD;
    }
    return (y*qexp(x,MOD-2,MOD)) % MOD;
}
int32_t main() 
{
	IAMSPEED
	cin >> n;
	FOR(i,1,n){
		cin >> L[i] >> R[i];
		points.pb(L[i]);
		points.pb(R[i]+1);
	}
	points.pb(-inf);
	sort(all(points)); 
	points.resize(unique(all(points))-points.begin());
	dbv(points);
	// my ith segment is points[i] to points[i+1]
	int m=points.size();
	FOR(i,0,m-2)sz[i]=points[i+1]-points[i];
	FOR(i,0,m-1)S[i]=1;
	FOR(i,1,n) {
		dba(S,0,m-1);
		int ls=lower_bound(all(points),L[i])-points.begin();
		int rs=lower_bound(all(points),R[i]+1)-points.begin();
		db2(ls,rs);
		DEC(j,rs-1,ls){
			DEC(k,min(sz[j],n),1){ 
				if(k>1)dp[j][k]=(dp[j][k]+dp[j][k-1])%MOD;
				else if(j)dp[j][k]=(dp[j][k]+S[j-1])%MOD;
				db3(j,k,dp[j][k]);
			}
		}
		
		memset(S,0,sizeof S);
		FOR(j,0,m-1){
			int val = 0;
			if(j==0){
				val=1;
			}
			FOR(k,1,min(n,sz[j])){
				val=(val+dp[j][k]*choose(sz[j],k)%MOD)%MOD;
			}
			if(j)S[j]=(S[j-1]+val)%MOD;
			else S[j]=1;
		}
	}
	cout<<(S[m-1]-1+MOD)%MOD;
}



# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2041 ms 648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2041 ms 648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 1308 KB Output is correct
2 Correct 746 ms 1312 KB Output is correct
3 Correct 807 ms 1312 KB Output is correct
4 Correct 756 ms 1312 KB Output is correct
5 Correct 757 ms 1308 KB Output is correct
6 Correct 772 ms 1264 KB Output is correct
7 Correct 741 ms 1260 KB Output is correct
8 Correct 719 ms 1304 KB Output is correct
9 Correct 702 ms 1276 KB Output is correct
10 Correct 704 ms 1228 KB Output is correct
11 Correct 711 ms 1304 KB Output is correct
12 Correct 717 ms 1312 KB Output is correct
13 Correct 711 ms 1352 KB Output is correct
14 Correct 713 ms 1272 KB Output is correct
15 Correct 710 ms 1312 KB Output is correct
16 Correct 306 ms 852 KB Output is correct
17 Correct 306 ms 860 KB Output is correct
18 Correct 307 ms 788 KB Output is correct
19 Correct 312 ms 856 KB Output is correct
20 Correct 330 ms 944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2041 ms 648 KB Time limit exceeded
2 Halted 0 ms 0 KB -