답안 #124998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124998 2019-07-04T10:19:54 Z Mamnoon_Siam Boat (APIO16_boat) C++17
100 / 100
766 ms 2552 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int mod = 1e9 + 7;

ll qpow(ll b, ll p) {
	ll ret = 1;
	while(p) {
		if(p & 1) ret = (ret * b) % mod;
		b = (b * b) % mod, p >>= 1;
	} return ret;
}

struct base {
	ll x;
	void fix() {
		if(x < 0 or x >= mod) x %= mod;
		if(x < 0) x += mod;
	}
	base() {x = 0;}
	base(int _x) { x = _x; fix(); }
	base(ll _x) { x = _x; fix(); }
	base operator + (const base &o) const {
		base ret;
		ret.x = x + o.x;
		if(ret.x >= mod) {
			ret.x -= mod;
		}
		return ret;
	}
	base operator * (const base &o) const { return base(x * o.x); }
	base operator / (const base &o) const {
		return base(x * qpow(o.x, mod - 2)); }
	void operator += (const base &o) { (*this) = (*this) + o; }
	void operator *= (const base &o) { (*this) = (*this) * o; }
};

const int maxn = 505;

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

int N_rng;
int l[maxn << 1], r[maxn << 1];

base inv[maxn];
base dp[maxn];
base RngC[maxn];
base C[maxn][maxn];
base g[maxn];

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	vector<int> tmp;
	for(int i = 1; i <= n; i++) {
		scanf("%d %d", &a[i], &b[i]);
		a[i]--;
		tmp.emplace_back(a[i]);
		tmp.emplace_back(b[i]);
	}

	sort(tmp.begin(), tmp.end());
	tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());

	for(int i = 1; i < tmp.size(); i++) {
		N_rng++;
		l[N_rng] = tmp[i - 1];
		r[N_rng] = tmp[i];
	}

	inv[0] = 1;
	for(int i = 1; i <= n; i++) {
		inv[i] = base(1) / i;
	}
	
	for(int i = 0; i <= n; i++) {
		C[i][0] = 1;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= i; j++) {
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
		}
	}
	
	dp[0] = 1;
	for(int rng = 1; rng <= N_rng; rng++) {
		RngC[0] = 1;
		for(int i = 1, sz = r[rng] - l[rng]; i <= n; i++, sz--) {
			RngC[i] = sz < 1 ? 0 : RngC[i - 1] * inv[i] * sz;
		}
		for(int k = 1; (g[k].x = 0) or k <= n; k++) {
			for(int i = 1; i <= k; i++) {
				g[k] += C[k - 1][i - 1] * RngC[i];
			}
		}
		for(int i = n; i >= 1; i--) {
			if(a[i] <= l[rng] and r[rng] <= b[i]) {
				int cnt = 0;
				for(int k = i; k >= 1; k--) {
					if(a[k] <= l[rng] and r[rng] <= b[k]) {
						cnt++;
					}
					dp[i] += dp[k - 1] * g[cnt];
				}
			}
		}
	}

	base ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += dp[i];
	}
	printf("%d\n", (int)ans.x);
	return 0;
}

Compilation message

boat.cpp: In function 'int main(int, const char**)':
boat.cpp:67:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < tmp.size(); i++) {
                 ~~^~~~~~~~~~~~
boat.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
boat.cpp:58: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 344 ms 2424 KB Output is correct
2 Correct 349 ms 2388 KB Output is correct
3 Correct 346 ms 2296 KB Output is correct
4 Correct 346 ms 2396 KB Output is correct
5 Correct 345 ms 2296 KB Output is correct
6 Correct 345 ms 2424 KB Output is correct
7 Correct 345 ms 2400 KB Output is correct
8 Correct 344 ms 2424 KB Output is correct
9 Correct 345 ms 2392 KB Output is correct
10 Correct 347 ms 2296 KB Output is correct
11 Correct 344 ms 2424 KB Output is correct
12 Correct 345 ms 2424 KB Output is correct
13 Correct 346 ms 2396 KB Output is correct
14 Correct 344 ms 2300 KB Output is correct
15 Correct 346 ms 2296 KB Output is correct
16 Correct 65 ms 2424 KB Output is correct
17 Correct 69 ms 2384 KB Output is correct
18 Correct 66 ms 2424 KB Output is correct
19 Correct 69 ms 2300 KB Output is correct
20 Correct 67 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 344 ms 2424 KB Output is correct
2 Correct 349 ms 2388 KB Output is correct
3 Correct 346 ms 2296 KB Output is correct
4 Correct 346 ms 2396 KB Output is correct
5 Correct 345 ms 2296 KB Output is correct
6 Correct 345 ms 2424 KB Output is correct
7 Correct 345 ms 2400 KB Output is correct
8 Correct 344 ms 2424 KB Output is correct
9 Correct 345 ms 2392 KB Output is correct
10 Correct 347 ms 2296 KB Output is correct
11 Correct 344 ms 2424 KB Output is correct
12 Correct 345 ms 2424 KB Output is correct
13 Correct 346 ms 2396 KB Output is correct
14 Correct 344 ms 2300 KB Output is correct
15 Correct 346 ms 2296 KB Output is correct
16 Correct 65 ms 2424 KB Output is correct
17 Correct 69 ms 2384 KB Output is correct
18 Correct 66 ms 2424 KB Output is correct
19 Correct 69 ms 2300 KB Output is correct
20 Correct 67 ms 2424 KB Output is correct
21 Correct 373 ms 2424 KB Output is correct
22 Correct 368 ms 2424 KB Output is correct
23 Correct 356 ms 2296 KB Output is correct
24 Correct 363 ms 2424 KB Output is correct
25 Correct 366 ms 2424 KB Output is correct
26 Correct 437 ms 2424 KB Output is correct
27 Correct 446 ms 2296 KB Output is correct
28 Correct 441 ms 2296 KB Output is correct
29 Correct 438 ms 2552 KB Output is correct
30 Correct 338 ms 2300 KB Output is correct
31 Correct 342 ms 2424 KB Output is correct
32 Correct 339 ms 2428 KB Output is correct
33 Correct 339 ms 2424 KB Output is correct
34 Correct 338 ms 2296 KB Output is correct
35 Correct 338 ms 2424 KB Output is correct
36 Correct 338 ms 2424 KB Output is correct
37 Correct 341 ms 2396 KB Output is correct
38 Correct 339 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 9 ms 2300 KB Output is correct
3 Correct 9 ms 2424 KB Output is correct
4 Correct 10 ms 2296 KB Output is correct
5 Correct 9 ms 2424 KB Output is correct
6 Correct 10 ms 2424 KB Output is correct
7 Correct 10 ms 2424 KB Output is correct
8 Correct 10 ms 2300 KB Output is correct
9 Correct 10 ms 2296 KB Output is correct
10 Correct 10 ms 2300 KB Output is correct
11 Correct 9 ms 2424 KB Output is correct
12 Correct 9 ms 2296 KB Output is correct
13 Correct 9 ms 2296 KB Output is correct
14 Correct 9 ms 2424 KB Output is correct
15 Correct 9 ms 2296 KB Output is correct
16 Correct 7 ms 2424 KB Output is correct
17 Correct 6 ms 2296 KB Output is correct
18 Correct 7 ms 2424 KB Output is correct
19 Correct 7 ms 2424 KB Output is correct
20 Correct 7 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 344 ms 2424 KB Output is correct
2 Correct 349 ms 2388 KB Output is correct
3 Correct 346 ms 2296 KB Output is correct
4 Correct 346 ms 2396 KB Output is correct
5 Correct 345 ms 2296 KB Output is correct
6 Correct 345 ms 2424 KB Output is correct
7 Correct 345 ms 2400 KB Output is correct
8 Correct 344 ms 2424 KB Output is correct
9 Correct 345 ms 2392 KB Output is correct
10 Correct 347 ms 2296 KB Output is correct
11 Correct 344 ms 2424 KB Output is correct
12 Correct 345 ms 2424 KB Output is correct
13 Correct 346 ms 2396 KB Output is correct
14 Correct 344 ms 2300 KB Output is correct
15 Correct 346 ms 2296 KB Output is correct
16 Correct 65 ms 2424 KB Output is correct
17 Correct 69 ms 2384 KB Output is correct
18 Correct 66 ms 2424 KB Output is correct
19 Correct 69 ms 2300 KB Output is correct
20 Correct 67 ms 2424 KB Output is correct
21 Correct 373 ms 2424 KB Output is correct
22 Correct 368 ms 2424 KB Output is correct
23 Correct 356 ms 2296 KB Output is correct
24 Correct 363 ms 2424 KB Output is correct
25 Correct 366 ms 2424 KB Output is correct
26 Correct 437 ms 2424 KB Output is correct
27 Correct 446 ms 2296 KB Output is correct
28 Correct 441 ms 2296 KB Output is correct
29 Correct 438 ms 2552 KB Output is correct
30 Correct 338 ms 2300 KB Output is correct
31 Correct 342 ms 2424 KB Output is correct
32 Correct 339 ms 2428 KB Output is correct
33 Correct 339 ms 2424 KB Output is correct
34 Correct 338 ms 2296 KB Output is correct
35 Correct 338 ms 2424 KB Output is correct
36 Correct 338 ms 2424 KB Output is correct
37 Correct 341 ms 2396 KB Output is correct
38 Correct 339 ms 2424 KB Output is correct
39 Correct 9 ms 2296 KB Output is correct
40 Correct 9 ms 2300 KB Output is correct
41 Correct 9 ms 2424 KB Output is correct
42 Correct 10 ms 2296 KB Output is correct
43 Correct 9 ms 2424 KB Output is correct
44 Correct 10 ms 2424 KB Output is correct
45 Correct 10 ms 2424 KB Output is correct
46 Correct 10 ms 2300 KB Output is correct
47 Correct 10 ms 2296 KB Output is correct
48 Correct 10 ms 2300 KB Output is correct
49 Correct 9 ms 2424 KB Output is correct
50 Correct 9 ms 2296 KB Output is correct
51 Correct 9 ms 2296 KB Output is correct
52 Correct 9 ms 2424 KB Output is correct
53 Correct 9 ms 2296 KB Output is correct
54 Correct 7 ms 2424 KB Output is correct
55 Correct 6 ms 2296 KB Output is correct
56 Correct 7 ms 2424 KB Output is correct
57 Correct 7 ms 2424 KB Output is correct
58 Correct 7 ms 2424 KB Output is correct
59 Correct 653 ms 2424 KB Output is correct
60 Correct 644 ms 2424 KB Output is correct
61 Correct 635 ms 2424 KB Output is correct
62 Correct 652 ms 2296 KB Output is correct
63 Correct 658 ms 2424 KB Output is correct
64 Correct 760 ms 2424 KB Output is correct
65 Correct 761 ms 2424 KB Output is correct
66 Correct 766 ms 2424 KB Output is correct
67 Correct 763 ms 2424 KB Output is correct
68 Correct 761 ms 2424 KB Output is correct
69 Correct 632 ms 2424 KB Output is correct
70 Correct 616 ms 2296 KB Output is correct
71 Correct 618 ms 2296 KB Output is correct
72 Correct 630 ms 2424 KB Output is correct
73 Correct 625 ms 2424 KB Output is correct
74 Correct 102 ms 2424 KB Output is correct
75 Correct 101 ms 2424 KB Output is correct
76 Correct 106 ms 2296 KB Output is correct
77 Correct 105 ms 2296 KB Output is correct
78 Correct 102 ms 2396 KB Output is correct