답안 #20867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20867 2017-02-27T04:48:00 Z kdh9949 Boat (APIO16_boat) C++14
9 / 100
379 ms 7324 KB
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

int n;
set<int> ss;
int a[505], b[505], seg[1005], c, q, t;
int dp[505][1005], dps[505][1005];
int ufac[505], dfacin[505], newcomb[1005][505];
int mod = 1000000007;

long long pow(long long n, int k){
	if(k == 1) return n;
	long long t = pow(n, k / 2);
	t *= t; t %= mod;
	if(k % 2) return t * n % mod;
	return t;
}

int modinv(int x){
	return (int)pow(x, mod - 2);
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d%d", a + i, b + i);
		ss.insert(a[i]); ss.insert(b[i] + 1);
	}
	ss.insert(0); ss.insert(1);
	for(set<int>::iterator it = ss.begin(); it != ss.end(); it++) seg[++c] = *it;
	for(int i = 1; i <= n; i++){
		a[i] = (int)(lower_bound(seg + 1, seg + c + 1, a[i]) - seg);
		b[i] = (int)(lower_bound(seg + 1, seg + c + 1, b[i] + 1) - seg);
	}
	dfacin[0] = modinv(2); q = 2;
	for(int i = 1; i < n; i++){
		q = (int)((long long)q * (i + 2) % mod);
		dfacin[i] = modinv(q);
	}
	for(int i = 1; i < c; i++){
		ufac[0] = (int)((long long)(seg[i + 1] - seg[i]) * (seg[i + 1] - seg[i] - 1) % mod);
		newcomb[i][0] = (int)((long long)ufac[0] * dfacin[0] % mod);
		for(int j = 1; j < n; j++){
			ufac[j] = (int)((long long)ufac[j - 1] * (seg[i + 1] - seg[i] + j) % mod);
			newcomb[i][j] = (int)((long long)ufac[j] * dfacin[j] % mod);
		}
	}
	dp[0][0] = 1;
	for(int i = 0; i < c; i++) dps[0][i] = 1;
	for(int i = 1; i <= n; i++){
		dps[i][0] = dps[i - 1][0];
		for(int j = 1; j < a[i]; j++) dps[i][j] = ((dps[i - 1][j] + dps[i][j - 1]) % mod - dps[i - 1][j - 1] + mod) % mod;
		for(int j = a[i]; j < b[i]; j++){
			dp[i][j] = dps[i - 1][j - 1];
			dps[i][j] = ((dps[i - 1][j] + dps[i][j - 1]) % mod - dps[i - 1][j - 1] + mod) % mod;
			dps[i][j] += (int)((long long)(seg[j + 1] - seg[j]) * dp[i][j] % mod);
			dps[i][j] %= mod;
			q = 0;
			for(int k = i - 1; k > 0; k--){
				if(a[k] <= j && j < b[k]){
					t = (int)((long long)newcomb[j][q] * dp[k][j] % mod);
					dps[i][j] += t;
					dps[i][j] %= mod;
					q++;
				}
			}
		}
		for(int j = b[i]; j < c; j++) dps[i][j] = ((dps[i - 1][j] + dps[i][j - 1]) % mod - dps[i - 1][j - 1] + mod) % mod;
	}
	printf("%d", (dps[n][c - 1] - 1 + mod) % mod);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:26:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
boat.cpp:28:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", a + i, b + i);
                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 7324 KB Output is correct
2 Correct 26 ms 7324 KB Output is correct
3 Correct 19 ms 7324 KB Output is correct
4 Correct 23 ms 7324 KB Output is correct
5 Correct 26 ms 7324 KB Output is correct
6 Correct 26 ms 7324 KB Output is correct
7 Correct 26 ms 7324 KB Output is correct
8 Correct 29 ms 7324 KB Output is correct
9 Correct 29 ms 7324 KB Output is correct
10 Correct 26 ms 7324 KB Output is correct
11 Correct 26 ms 7324 KB Output is correct
12 Correct 29 ms 7324 KB Output is correct
13 Correct 29 ms 7324 KB Output is correct
14 Correct 23 ms 7324 KB Output is correct
15 Correct 26 ms 7324 KB Output is correct
16 Correct 6 ms 7324 KB Output is correct
17 Correct 6 ms 7324 KB Output is correct
18 Correct 6 ms 7324 KB Output is correct
19 Correct 3 ms 7324 KB Output is correct
20 Correct 6 ms 7324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 7324 KB Output is correct
2 Correct 26 ms 7324 KB Output is correct
3 Correct 19 ms 7324 KB Output is correct
4 Correct 23 ms 7324 KB Output is correct
5 Correct 26 ms 7324 KB Output is correct
6 Correct 26 ms 7324 KB Output is correct
7 Correct 26 ms 7324 KB Output is correct
8 Correct 29 ms 7324 KB Output is correct
9 Correct 29 ms 7324 KB Output is correct
10 Correct 26 ms 7324 KB Output is correct
11 Correct 26 ms 7324 KB Output is correct
12 Correct 29 ms 7324 KB Output is correct
13 Correct 29 ms 7324 KB Output is correct
14 Correct 23 ms 7324 KB Output is correct
15 Correct 26 ms 7324 KB Output is correct
16 Correct 6 ms 7324 KB Output is correct
17 Correct 6 ms 7324 KB Output is correct
18 Correct 6 ms 7324 KB Output is correct
19 Correct 3 ms 7324 KB Output is correct
20 Correct 6 ms 7324 KB Output is correct
21 Incorrect 379 ms 7324 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 7324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 7324 KB Output is correct
2 Correct 26 ms 7324 KB Output is correct
3 Correct 19 ms 7324 KB Output is correct
4 Correct 23 ms 7324 KB Output is correct
5 Correct 26 ms 7324 KB Output is correct
6 Correct 26 ms 7324 KB Output is correct
7 Correct 26 ms 7324 KB Output is correct
8 Correct 29 ms 7324 KB Output is correct
9 Correct 29 ms 7324 KB Output is correct
10 Correct 26 ms 7324 KB Output is correct
11 Correct 26 ms 7324 KB Output is correct
12 Correct 29 ms 7324 KB Output is correct
13 Correct 29 ms 7324 KB Output is correct
14 Correct 23 ms 7324 KB Output is correct
15 Correct 26 ms 7324 KB Output is correct
16 Correct 6 ms 7324 KB Output is correct
17 Correct 6 ms 7324 KB Output is correct
18 Correct 6 ms 7324 KB Output is correct
19 Correct 3 ms 7324 KB Output is correct
20 Correct 6 ms 7324 KB Output is correct
21 Incorrect 379 ms 7324 KB Output isn't correct
22 Halted 0 ms 0 KB -