답안 #793356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793356 2023-07-25T18:18:04 Z kingfran1907 Boat (APIO16_boat) C++14
9 / 100
156 ms 2388 KB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long llint;
 
const int maxn = 1010;
const int mod = 1e9+7;
 
int mul(int a, int b) {
	llint out = (llint)a * b;
	return out % mod;
}
 
int pot(int a, int b) {
	if (b == 0) return 1;
	if (b % 2 == 1) return pot(a, b - 1);
	
	int out = pot(a, b / 2);
	return mul(out, out);
}
 
int n;
int a[maxn], b[maxn];
int fac[maxn];
int dp[maxn][maxn];
int inv[maxn];
int len[maxn];
 
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", a+i, b+i);
	vector< int > v;
	for (int i = 0; i <= n; i++) {
		v.push_back(a[i]);
		v.push_back(b[i] + 1);
	}
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	for (int i = 0; i <= n; i++) {
		a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
		b[i] = lower_bound(v.begin(), v.end(), b[i] + 1) - v.begin() - 1;
	}
	for (int i = 0; i < v.size() - 1; i++) len[i] = v[i + 1] - v[i];
	//for (int i = 0; i < v.size() - 1; i++) printf("%d ", len[i]); printf("\n\n");
	
	for (int i = 1; i <= n; i++) inv[i] = pot(i, mod - 2);
	for (int i = 0; i < v.size() - 1; i++) dp[0][i] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < v.size() - 1; j++) {
			dp[i][j] = dp[i][j - 1];
			if (a[i] <= j && j <= b[i]) {
				int kol = 1;
				int pov = len[j];
				int suma = pov;
				for (int k = i - 1; k >= 0; k--) {
					//printf("%d %d --> %d --- %d %d\n", i, j, k, dp[k][j - 1], suma);
					dp[i][j] += mul(dp[k][j - 1], suma), dp[i][j] %= mod;
					if (a[k] <= j && j <= b[k]) {
						kol++;
						if (kol <= len[j]) {
							pov = mul(pov, mul(len[j] - kol + 1, inv[kol]));
							suma += pov;
						}
					}
				}
			}
		}
		//for (int j = 0; j < v.size() - 1; j++) printf("%d ", dp[i][j]);
		//printf("\n");
	}
	
	int sum = 0;
	for (int i = 1; i <= n; i++) sum += dp[i][v.size() - 2], sum %= mod;
	printf("%d\n", sum);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (int i = 0; i < v.size() - 1; i++) len[i] = v[i + 1] - v[i];
      |                  ~~^~~~~~~~~~~~~~
boat.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for (int i = 0; i < v.size() - 1; i++) dp[0][i] = 1;
      |                  ~~^~~~~~~~~~~~~~
boat.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for (int j = 1; j < v.size() - 1; j++) {
      |                   ~~^~~~~~~~~~~~~~
boat.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
boat.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%d%d", a+i, b+i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 3 ms 2240 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2232 KB Output is correct
7 Correct 3 ms 2260 KB Output is correct
8 Correct 3 ms 2388 KB Output is correct
9 Correct 3 ms 2260 KB Output is correct
10 Correct 3 ms 2236 KB Output is correct
11 Correct 3 ms 2236 KB Output is correct
12 Correct 3 ms 2260 KB Output is correct
13 Correct 3 ms 2240 KB Output is correct
14 Correct 3 ms 2260 KB Output is correct
15 Correct 3 ms 2240 KB Output is correct
16 Correct 2 ms 2236 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 3 ms 2240 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2232 KB Output is correct
7 Correct 3 ms 2260 KB Output is correct
8 Correct 3 ms 2388 KB Output is correct
9 Correct 3 ms 2260 KB Output is correct
10 Correct 3 ms 2236 KB Output is correct
11 Correct 3 ms 2236 KB Output is correct
12 Correct 3 ms 2260 KB Output is correct
13 Correct 3 ms 2240 KB Output is correct
14 Correct 3 ms 2260 KB Output is correct
15 Correct 3 ms 2240 KB Output is correct
16 Correct 2 ms 2236 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Incorrect 156 ms 2228 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
3 Correct 3 ms 2240 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2232 KB Output is correct
7 Correct 3 ms 2260 KB Output is correct
8 Correct 3 ms 2388 KB Output is correct
9 Correct 3 ms 2260 KB Output is correct
10 Correct 3 ms 2236 KB Output is correct
11 Correct 3 ms 2236 KB Output is correct
12 Correct 3 ms 2260 KB Output is correct
13 Correct 3 ms 2240 KB Output is correct
14 Correct 3 ms 2260 KB Output is correct
15 Correct 3 ms 2240 KB Output is correct
16 Correct 2 ms 2236 KB Output is correct
17 Correct 2 ms 2260 KB Output is correct
18 Correct 2 ms 2260 KB Output is correct
19 Correct 2 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Incorrect 156 ms 2228 KB Output isn't correct
22 Halted 0 ms 0 KB -