Submission #43370

# Submission time Handle Problem Language Result Execution time Memory
43370 2018-03-15T04:29:20 Z top34051 Boat (APIO16_boat) C++14
0 / 100
111 ms 14280 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define X first
#define Y second

const int maxn = 2e3 + 5;
const ll mod = 1e9 + 7;

int n,m;
int a[maxn], b[maxn];

vector<int> pos;
pii itv[maxn];
ll temp[maxn][maxn];
ll rec[maxn][maxn];

ll dp[maxn][maxn];

ll fac[maxn], invfac[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 x, ll y) { return 1<x ? y - inv(y%x, x)*y/x : 1; }

ll combi1(ll x, ll y) {
    return x<y ? 0 : mul(fac[x], mul(invfac[y], invfac[x-y]));
}

void init() {
	//get interval
	pos.push_back(0); pos.push_back(2e9);
	for(int i=1;i<=n;i++) {
		pos.push_back(a[i]);
		pos.push_back(b[i]);
	}
	sort(pos.begin(),pos.end());
	pos.erase(unique(pos.begin(),pos.end()),pos.end());
	for(int i=0;i<pos.size();i++) {
		if(i!=0 && pos[i-1]+1<=pos[i]-1) itv[++m] = {pos[i-1]+1,pos[i]-1};
		itv[++m] = {pos[i],pos[i]};
	}
//	for(int i=1;i<=m;i++) printf("[%d, %d] ",itv[i].X,itv[i].Y);
//	printf("\n");
	//fac and invfac
	fac[0] = 1; invfac[0] = inv(fac[0], mod);
//    printf("fac %d = %lld inv = %lld\n",1,fac[1],invfac[1]);
	for(int i=1;i<=m;i++) {
		fac[i] = mul(fac[i-1], i);
		invfac[i] = inv(fac[i], mod);
//		printf("fac %d = %lld inv = %lld\n",i,fac[i],invfac[i]);
	}
	//precompute
	for(int i=1;i<=m;i++) {
        ll sz = itv[i].Y-itv[i].X+1;
        temp[i][1] = sz;
        for(int use=2;use<=n;use++) temp[i][use] = mul(temp[i][use-1], mul(sz-use+1, inv(use,mod)));
	}
	return ;
	for(int i=1;i<=m;i++) {
        for(int cnt=1;cnt<=n;cnt++) {
        	for(int use=1;use<=cnt;use++) rec[i][cnt] = add(rec[i][cnt], mul(temp[i][use], combi1(cnt-1,use-1)));
		}
	}
}

ll solve() {
    ll res = 0;
	for(int i=1;i<=m;i++) dp[0][i] = 1;
	for(int i=1;i<=m;i++) {
		for(int x=1;x<=n;x++) {
			dp[x][i] = dp[x][i-1];
			if(a[x]<=itv[i].X && itv[i].Y<=b[x]) {
				ll cnt = 1;
				for(int y=x-1;y>=0;y--) {
					dp[x][i] = add(dp[x][i], mul(dp[y][i-1], rec[i][cnt]));
					if(a[y]<=itv[i].X && itv[i].Y<=b[y]) cnt++;
				}
			}
//			printf("dp %d %d = %lld\n",x,i,dp[x][i]);
		}
	}
	for(int x=1;x<=n;x++) res = add(res, dp[x][m]);
	return res;
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	init();
	printf("%lld",solve());
}

Compilation message

boat.cpp: In function 'void init()':
boat.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<pos.size();i++) {
               ^
boat.cpp: In function 'int main()':
boat.cpp:92:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
boat.cpp:93:49: 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 Incorrect 111 ms 14280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 14280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 14280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 14280 KB Output isn't correct
2 Halted 0 ms 0 KB -