답안 #640402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640402 2022-09-14T14:47:07 Z imtore Boat (APIO16_boat) C++17
9 / 100
12 ms 2428 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
#define ll long long
#define MOD 1'000'000'007
using namespace std;
 
int A[521], B[521];
 
vector<int> X;
 
ll inv[521];
ll dp1[521], dp2[521][521], sum[521];
 
ll get_inv(ll x, ll y = MOD-2){
	ll z = y & 1 ? x : 1;
	while(y >>= 1){
		if(y & 1) z = z*x%MOD;
		x = x*x%MOD;
	}
	return z;
}
 
int main(){
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d %d", &A[i], &B[i]);
 
	for(int i = 1; i <= n; i++){
		X.push_back(A[i]);
		X.push_back(B[i]+1);
	}
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());
 
	for(int i = 1; i <= n; i++){
		A[i] = lower_bound(X.begin(), X.end(), A[i])-X.begin()+1;
		B[i] = lower_bound(X.begin(), X.end(), B[i]+1)-X.begin();
	}
 
	for(int i = 1; i <= n; i++) inv[i] = get_inv(i);
 
	dp1[0] = 1;
	for(int i = 1; i < X.size(); i++){
		for(int j = 0; j <= n; j++) dp2[j][0] = dp1[j];
		fill(sum, sum+n+1, 0);
		fill(dp1, dp1+n+1, 0);
		
		int cnt = 0;
		sum[0] = dp1[0] = dp2[0][0];
		for(int j = 1; j <= n; j++){
			if(A[j] <= i && B[j] >= i){
				int l = X[i]-X[i-1]; cnt++;
				for(int k = min(cnt, l); k >= 1; k--){
					dp2[j][k] = sum[k-1]*(l-k+1)%MOD*inv[k]%MOD;
					dp1[j] = (dp1[j]+dp2[j][k])%MOD;
					sum[k] = (sum[k]+dp2[j][k])%MOD;
				}
			}
			dp1[j] = (dp1[j]+dp2[j][0])%MOD;
			sum[0] = (sum[0]+dp2[j][0])%MOD;
		}
	}
	
	ll ans = 0;
	for(int i = 1; i <= n; i++) ans = (ans+dp1[i])%MOD;
	printf("%lld", ans);
 
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i = 1; i < X.size(); i++){
      |                 ~~^~~~~~~~~~
boat.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
boat.cpp:26:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  for(int i = 1; i <= n; i++) scanf("%d %d", &A[i], &B[i]);
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2260 KB Output is correct
2 Correct 7 ms 2260 KB Output is correct
3 Correct 5 ms 2260 KB Output is correct
4 Correct 6 ms 2360 KB Output is correct
5 Correct 7 ms 2428 KB Output is correct
6 Correct 6 ms 2260 KB Output is correct
7 Correct 6 ms 2260 KB Output is correct
8 Correct 7 ms 2260 KB Output is correct
9 Correct 6 ms 2328 KB Output is correct
10 Correct 6 ms 2228 KB Output is correct
11 Correct 5 ms 2332 KB Output is correct
12 Correct 5 ms 2328 KB Output is correct
13 Correct 5 ms 2332 KB Output is correct
14 Correct 5 ms 2228 KB Output is correct
15 Correct 5 ms 2224 KB Output is correct
16 Correct 3 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2224 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2260 KB Output is correct
2 Correct 7 ms 2260 KB Output is correct
3 Correct 5 ms 2260 KB Output is correct
4 Correct 6 ms 2360 KB Output is correct
5 Correct 7 ms 2428 KB Output is correct
6 Correct 6 ms 2260 KB Output is correct
7 Correct 6 ms 2260 KB Output is correct
8 Correct 7 ms 2260 KB Output is correct
9 Correct 6 ms 2328 KB Output is correct
10 Correct 6 ms 2228 KB Output is correct
11 Correct 5 ms 2332 KB Output is correct
12 Correct 5 ms 2328 KB Output is correct
13 Correct 5 ms 2332 KB Output is correct
14 Correct 5 ms 2228 KB Output is correct
15 Correct 5 ms 2224 KB Output is correct
16 Correct 3 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2224 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Incorrect 12 ms 2348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2260 KB Output is correct
2 Correct 7 ms 2260 KB Output is correct
3 Correct 5 ms 2260 KB Output is correct
4 Correct 6 ms 2360 KB Output is correct
5 Correct 7 ms 2428 KB Output is correct
6 Correct 6 ms 2260 KB Output is correct
7 Correct 6 ms 2260 KB Output is correct
8 Correct 7 ms 2260 KB Output is correct
9 Correct 6 ms 2328 KB Output is correct
10 Correct 6 ms 2228 KB Output is correct
11 Correct 5 ms 2332 KB Output is correct
12 Correct 5 ms 2328 KB Output is correct
13 Correct 5 ms 2332 KB Output is correct
14 Correct 5 ms 2228 KB Output is correct
15 Correct 5 ms 2224 KB Output is correct
16 Correct 3 ms 2260 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2224 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Incorrect 12 ms 2348 KB Output isn't correct
22 Halted 0 ms 0 KB -