답안 #63238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63238 2018-08-01T06:46:30 Z kingpig9 Boat (APIO16_boat) C++11
100 / 100
749 ms 5364 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2018, MOD = 1e9 + 7;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))

inline void addeq (int &x, int y) {
	x += y;
	if (x >= MOD) {
		x -= MOD;
	}
}

inline int add (int x, int y) {
	addeq(x, y);
	return x;
}

inline int subtr (int x, int y) {
	x -= y;
	if (x < 0) {
		x += MOD;
	}
	return x;
}

inline int mult (int x, int y) {
	return ll(x) * y % MOD;
}

inline void multeq (int &x, int y) {
	x = mult(x, y);
}

int N;
int A[MAXN], B[MAXN];
int inda[MAXN], indb[MAXN];
vector<int> vals;
int len[MAXN];
int dp[MAXN][MAXN];	//dp[position][Where is your thing?]
int pdp[MAXN][MAXN];
int inv[MAXN];

int main() {
	//precomputation
	inv[1] = 1;
	for (int i = 2; i < MAXN; i++) {
		inv[i] = mult(inv[MOD % i], MOD - MOD / i);
	}

	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &A[i], &B[i]);
		B[i]++;
		vals.push_back(A[i]);
		vals.push_back(B[i]);
	}

	sort(all(vals));
	vals.resize(unique(all(vals)) - vals.begin());
	for (int i = 1; i <= N; i++) {
		A[i] = lower_bound(all(vals), A[i]) - vals.begin();
		B[i] = lower_bound(all(vals), B[i]) - vals.begin();
	}
	for (int i = 1; i < vals.size(); i++) {
		len[i] = vals[i] - vals[i - 1];
	}

	for (int i = 0; i < vals.size(); i++) {
		dp[0][i] = 1;
	}

	for (int i = 0; i < vals.size(); i++) {
		dp[0][i] = 1;
	}

	for (int i = 1; i <= N; i++) {
		for (int j = A[i] + 1; j <= B[i]; j++) {
			dp[i][j] = mult(len[j], dp[i - 1][j - 1]);
			int cho = len[j] - 1;
			int npos = 1;
			for (int k = i - 1; k >= 1; k--) {
				if (A[k] + 1 <= j && j <= B[k]) {
					npos++;
					multeq(cho, mult(len[j] + npos - 2, inv[npos]));	//did thru examples...not as clear at first, but you will understand.
					addeq(dp[i][j], mult(cho, dp[k - 1][j - 1]));
				}
			}
		}

		dp[i][0] = 1;
		for (int j = 1; j < vals.size(); j++) {
			addeq(dp[i][j], subtr(add(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]));
		}
	}
	printf("%d\n", subtr(dp[N][vals.size() - 1], 1));
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:74:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < vals.size(); i++) {
                  ~~^~~~~~~~~~~~~
boat.cpp:78:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < vals.size(); i++) {
                  ~~^~~~~~~~~~~~~
boat.cpp:82:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < vals.size(); i++) {
                  ~~^~~~~~~~~~~~~
boat.cpp:101:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 1; j < vals.size(); j++) {
                   ~~^~~~~~~~~~~~~
boat.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
boat.cpp:62:8: 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 9 ms 4340 KB Output is correct
2 Correct 10 ms 4340 KB Output is correct
3 Correct 9 ms 4400 KB Output is correct
4 Correct 8 ms 4464 KB Output is correct
5 Correct 11 ms 4468 KB Output is correct
6 Correct 8 ms 4484 KB Output is correct
7 Correct 9 ms 4572 KB Output is correct
8 Correct 9 ms 4584 KB Output is correct
9 Correct 9 ms 4608 KB Output is correct
10 Correct 8 ms 4608 KB Output is correct
11 Correct 10 ms 4624 KB Output is correct
12 Correct 8 ms 4632 KB Output is correct
13 Correct 9 ms 4644 KB Output is correct
14 Correct 10 ms 4656 KB Output is correct
15 Correct 10 ms 4668 KB Output is correct
16 Correct 7 ms 4668 KB Output is correct
17 Correct 5 ms 4668 KB Output is correct
18 Correct 7 ms 4668 KB Output is correct
19 Correct 6 ms 4668 KB Output is correct
20 Correct 6 ms 4668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4340 KB Output is correct
2 Correct 10 ms 4340 KB Output is correct
3 Correct 9 ms 4400 KB Output is correct
4 Correct 8 ms 4464 KB Output is correct
5 Correct 11 ms 4468 KB Output is correct
6 Correct 8 ms 4484 KB Output is correct
7 Correct 9 ms 4572 KB Output is correct
8 Correct 9 ms 4584 KB Output is correct
9 Correct 9 ms 4608 KB Output is correct
10 Correct 8 ms 4608 KB Output is correct
11 Correct 10 ms 4624 KB Output is correct
12 Correct 8 ms 4632 KB Output is correct
13 Correct 9 ms 4644 KB Output is correct
14 Correct 10 ms 4656 KB Output is correct
15 Correct 10 ms 4668 KB Output is correct
16 Correct 7 ms 4668 KB Output is correct
17 Correct 5 ms 4668 KB Output is correct
18 Correct 7 ms 4668 KB Output is correct
19 Correct 6 ms 4668 KB Output is correct
20 Correct 6 ms 4668 KB Output is correct
21 Correct 358 ms 4668 KB Output is correct
22 Correct 408 ms 4668 KB Output is correct
23 Correct 336 ms 4668 KB Output is correct
24 Correct 356 ms 4668 KB Output is correct
25 Correct 289 ms 4668 KB Output is correct
26 Correct 516 ms 4668 KB Output is correct
27 Correct 522 ms 4668 KB Output is correct
28 Correct 464 ms 4668 KB Output is correct
29 Correct 470 ms 4668 KB Output is correct
30 Correct 10 ms 4888 KB Output is correct
31 Correct 11 ms 4912 KB Output is correct
32 Correct 9 ms 4912 KB Output is correct
33 Correct 11 ms 4916 KB Output is correct
34 Correct 10 ms 4916 KB Output is correct
35 Correct 12 ms 4916 KB Output is correct
36 Correct 12 ms 4964 KB Output is correct
37 Correct 12 ms 4964 KB Output is correct
38 Correct 11 ms 4976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4976 KB Output is correct
2 Correct 5 ms 4976 KB Output is correct
3 Correct 5 ms 4976 KB Output is correct
4 Correct 5 ms 4976 KB Output is correct
5 Correct 8 ms 4976 KB Output is correct
6 Correct 8 ms 4976 KB Output is correct
7 Correct 11 ms 4976 KB Output is correct
8 Correct 7 ms 4976 KB Output is correct
9 Correct 6 ms 4976 KB Output is correct
10 Correct 8 ms 4976 KB Output is correct
11 Correct 6 ms 4976 KB Output is correct
12 Correct 6 ms 4976 KB Output is correct
13 Correct 6 ms 4976 KB Output is correct
14 Correct 7 ms 4976 KB Output is correct
15 Correct 6 ms 4976 KB Output is correct
16 Correct 5 ms 4976 KB Output is correct
17 Correct 5 ms 4976 KB Output is correct
18 Correct 6 ms 4976 KB Output is correct
19 Correct 4 ms 4976 KB Output is correct
20 Correct 5 ms 4976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4340 KB Output is correct
2 Correct 10 ms 4340 KB Output is correct
3 Correct 9 ms 4400 KB Output is correct
4 Correct 8 ms 4464 KB Output is correct
5 Correct 11 ms 4468 KB Output is correct
6 Correct 8 ms 4484 KB Output is correct
7 Correct 9 ms 4572 KB Output is correct
8 Correct 9 ms 4584 KB Output is correct
9 Correct 9 ms 4608 KB Output is correct
10 Correct 8 ms 4608 KB Output is correct
11 Correct 10 ms 4624 KB Output is correct
12 Correct 8 ms 4632 KB Output is correct
13 Correct 9 ms 4644 KB Output is correct
14 Correct 10 ms 4656 KB Output is correct
15 Correct 10 ms 4668 KB Output is correct
16 Correct 7 ms 4668 KB Output is correct
17 Correct 5 ms 4668 KB Output is correct
18 Correct 7 ms 4668 KB Output is correct
19 Correct 6 ms 4668 KB Output is correct
20 Correct 6 ms 4668 KB Output is correct
21 Correct 358 ms 4668 KB Output is correct
22 Correct 408 ms 4668 KB Output is correct
23 Correct 336 ms 4668 KB Output is correct
24 Correct 356 ms 4668 KB Output is correct
25 Correct 289 ms 4668 KB Output is correct
26 Correct 516 ms 4668 KB Output is correct
27 Correct 522 ms 4668 KB Output is correct
28 Correct 464 ms 4668 KB Output is correct
29 Correct 470 ms 4668 KB Output is correct
30 Correct 10 ms 4888 KB Output is correct
31 Correct 11 ms 4912 KB Output is correct
32 Correct 9 ms 4912 KB Output is correct
33 Correct 11 ms 4916 KB Output is correct
34 Correct 10 ms 4916 KB Output is correct
35 Correct 12 ms 4916 KB Output is correct
36 Correct 12 ms 4964 KB Output is correct
37 Correct 12 ms 4964 KB Output is correct
38 Correct 11 ms 4976 KB Output is correct
39 Correct 6 ms 4976 KB Output is correct
40 Correct 5 ms 4976 KB Output is correct
41 Correct 5 ms 4976 KB Output is correct
42 Correct 5 ms 4976 KB Output is correct
43 Correct 8 ms 4976 KB Output is correct
44 Correct 8 ms 4976 KB Output is correct
45 Correct 11 ms 4976 KB Output is correct
46 Correct 7 ms 4976 KB Output is correct
47 Correct 6 ms 4976 KB Output is correct
48 Correct 8 ms 4976 KB Output is correct
49 Correct 6 ms 4976 KB Output is correct
50 Correct 6 ms 4976 KB Output is correct
51 Correct 6 ms 4976 KB Output is correct
52 Correct 7 ms 4976 KB Output is correct
53 Correct 6 ms 4976 KB Output is correct
54 Correct 5 ms 4976 KB Output is correct
55 Correct 5 ms 4976 KB Output is correct
56 Correct 6 ms 4976 KB Output is correct
57 Correct 4 ms 4976 KB Output is correct
58 Correct 5 ms 4976 KB Output is correct
59 Correct 367 ms 5072 KB Output is correct
60 Correct 320 ms 5144 KB Output is correct
61 Correct 294 ms 5160 KB Output is correct
62 Correct 343 ms 5192 KB Output is correct
63 Correct 431 ms 5192 KB Output is correct
64 Correct 600 ms 5192 KB Output is correct
65 Correct 635 ms 5192 KB Output is correct
66 Correct 644 ms 5228 KB Output is correct
67 Correct 749 ms 5344 KB Output is correct
68 Correct 622 ms 5364 KB Output is correct
69 Correct 288 ms 5364 KB Output is correct
70 Correct 293 ms 5364 KB Output is correct
71 Correct 359 ms 5364 KB Output is correct
72 Correct 240 ms 5364 KB Output is correct
73 Correct 297 ms 5364 KB Output is correct
74 Correct 101 ms 5364 KB Output is correct
75 Correct 75 ms 5364 KB Output is correct
76 Correct 82 ms 5364 KB Output is correct
77 Correct 92 ms 5364 KB Output is correct
78 Correct 68 ms 5364 KB Output is correct