답안 #1032691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032691 2024-07-24T06:15:54 Z Kerim Boat (APIO16_boat) C++17
100 / 100
1186 ms 1916 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define sz(v) (int)(v).size()
 
const int md = (int)1e9 + 7;
 
const int N = 505;
 
vector<int> fct(N), inv(N), inv_fct(N);
 
int pw(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1) res = (ll)res * x % md;
 
        x = (ll)x * x % md; y >>= 1;
    }
 
    return res;
}
 
int C(int n, int r) {
    int x = 1;
    for (int i = 1; i <= r; i++) x = (ll)x * (n - r + i) % md;
 
    return (ll)x * inv_fct[r] % md;
}
int rdp[N][N], p[N];
int rec(int x, int y, vector<int>&v){
	if (x < 0)
		return 0;
	if (y == 1)
		return (rec(x-1, y, v) + p[v[x] - 1]) % md;	
	int &ret = rdp[x][y];
	if (~ret)
		return ret;
	return ret = (rec(x-1, y, v) + rec(x-1, y-1, v)) % md;
}
int main() {
	// freopen("file.in", "r", stdin);
    ios::sync_with_stdio(false); cin.tie(nullptr);
 
    fct[0] = inv[0] = inv_fct[0] = 1;
    for (int i = 1; i < N; i++) {
        inv[i] = pw(i, md - 2);
        fct[i] = (ll)fct[i - 1] * i % md;
        inv_fct[i] = pw(fct[i], md - 2);
    }
 
    int n;
    cin >> n;
 
    map<int, vector<int>> m;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
 
        m[a[i]].push_back(i);
        m[b[i] + 1].push_back(-i);
    }
 
    vector<int> mv;
    for (auto i : m) mv.push_back(i.first);
 
    set<int> s;
    vector<int> dp(n + 1);
    for (int ii = 0; ii + 1 < sz(mv); ii++) {
        for (auto j : m[mv[ii]]) {
            if (0 < j) s.insert(j);
            else s.erase(-j); 
        }
 
        int R = mv[ii + 1] - mv[ii];

        vector<int> v(s.begin(), s.end()), nw_dp = dp;
        
        vector<int> c(sz(v));
        for (int j = 1; j < c.size(); j++)
        	c[j] = C(R, j + 1);

        memset(rdp, -1, sizeof rdp);

        p[0] = 1;
        for (int j = 1; j <= n; j++) 
        	p[j] = (p[j - 1] + dp[j]) % md;

        for (int i = 0; i < sz(v); i++) {
 
            nw_dp[v[i]] = (dp[v[i]] + (ll)p[v[i] - 1] * R % md) % md;
 
            for (int j = 1; j <= min(i, R - 1); j++) {
                nw_dp[v[i]] = (nw_dp[v[i]] + (ll)rec(i-1, j, v) * c[j] % md) % md;

                // x = (ll)fct[j - 1] * inv_fct[j - 1] % md;
                // for (int k = i - j; k >= 0; k--) {
                //     if (k != i - j) x = ((ll)x * (i - k - 1) % md) * inv[i - k - j] % md;
 
                //     nw_dp[v[i]] = (nw_dp[v[i]] + ((ll)p[v[k] - 1] * x % md) * c % md) % md;
                // }
            }
        }
 
        dp = nw_dp;
    }
 
    int sm = 0;
    for (auto i : dp) sm = (sm + i) % md;
 
    cout << sm << '\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:81:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for (int j = 1; j < c.size(); j++)
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1372 KB Output is correct
2 Correct 25 ms 1592 KB Output is correct
3 Correct 22 ms 1368 KB Output is correct
4 Correct 23 ms 1372 KB Output is correct
5 Correct 23 ms 1592 KB Output is correct
6 Correct 22 ms 1372 KB Output is correct
7 Correct 23 ms 1372 KB Output is correct
8 Correct 24 ms 1372 KB Output is correct
9 Correct 24 ms 1372 KB Output is correct
10 Correct 22 ms 1592 KB Output is correct
11 Correct 22 ms 1592 KB Output is correct
12 Correct 22 ms 1372 KB Output is correct
13 Correct 22 ms 1588 KB Output is correct
14 Correct 23 ms 1592 KB Output is correct
15 Correct 23 ms 1372 KB Output is correct
16 Correct 5 ms 1368 KB Output is correct
17 Correct 5 ms 1372 KB Output is correct
18 Correct 5 ms 1372 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 5 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1372 KB Output is correct
2 Correct 25 ms 1592 KB Output is correct
3 Correct 22 ms 1368 KB Output is correct
4 Correct 23 ms 1372 KB Output is correct
5 Correct 23 ms 1592 KB Output is correct
6 Correct 22 ms 1372 KB Output is correct
7 Correct 23 ms 1372 KB Output is correct
8 Correct 24 ms 1372 KB Output is correct
9 Correct 24 ms 1372 KB Output is correct
10 Correct 22 ms 1592 KB Output is correct
11 Correct 22 ms 1592 KB Output is correct
12 Correct 22 ms 1372 KB Output is correct
13 Correct 22 ms 1588 KB Output is correct
14 Correct 23 ms 1592 KB Output is correct
15 Correct 23 ms 1372 KB Output is correct
16 Correct 5 ms 1368 KB Output is correct
17 Correct 5 ms 1372 KB Output is correct
18 Correct 5 ms 1372 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 5 ms 1368 KB Output is correct
21 Correct 217 ms 1620 KB Output is correct
22 Correct 212 ms 1620 KB Output is correct
23 Correct 183 ms 1632 KB Output is correct
24 Correct 210 ms 1616 KB Output is correct
25 Correct 209 ms 1628 KB Output is correct
26 Correct 402 ms 1916 KB Output is correct
27 Correct 421 ms 1624 KB Output is correct
28 Correct 434 ms 1672 KB Output is correct
29 Correct 414 ms 1624 KB Output is correct
30 Correct 22 ms 1372 KB Output is correct
31 Correct 22 ms 1372 KB Output is correct
32 Correct 24 ms 1368 KB Output is correct
33 Correct 23 ms 1588 KB Output is correct
34 Correct 23 ms 1624 KB Output is correct
35 Correct 23 ms 1372 KB Output is correct
36 Correct 22 ms 1584 KB Output is correct
37 Correct 22 ms 1592 KB Output is correct
38 Correct 23 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1372 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1368 KB Output is correct
4 Correct 9 ms 1372 KB Output is correct
5 Correct 9 ms 1500 KB Output is correct
6 Correct 15 ms 1368 KB Output is correct
7 Correct 14 ms 1512 KB Output is correct
8 Correct 16 ms 1372 KB Output is correct
9 Correct 17 ms 1508 KB Output is correct
10 Correct 15 ms 1372 KB Output is correct
11 Correct 9 ms 1372 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 8 ms 1496 KB Output is correct
14 Correct 9 ms 1368 KB Output is correct
15 Correct 9 ms 1372 KB Output is correct
16 Correct 5 ms 1372 KB Output is correct
17 Correct 5 ms 1372 KB Output is correct
18 Correct 6 ms 1624 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 5 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1372 KB Output is correct
2 Correct 25 ms 1592 KB Output is correct
3 Correct 22 ms 1368 KB Output is correct
4 Correct 23 ms 1372 KB Output is correct
5 Correct 23 ms 1592 KB Output is correct
6 Correct 22 ms 1372 KB Output is correct
7 Correct 23 ms 1372 KB Output is correct
8 Correct 24 ms 1372 KB Output is correct
9 Correct 24 ms 1372 KB Output is correct
10 Correct 22 ms 1592 KB Output is correct
11 Correct 22 ms 1592 KB Output is correct
12 Correct 22 ms 1372 KB Output is correct
13 Correct 22 ms 1588 KB Output is correct
14 Correct 23 ms 1592 KB Output is correct
15 Correct 23 ms 1372 KB Output is correct
16 Correct 5 ms 1368 KB Output is correct
17 Correct 5 ms 1372 KB Output is correct
18 Correct 5 ms 1372 KB Output is correct
19 Correct 5 ms 1372 KB Output is correct
20 Correct 5 ms 1368 KB Output is correct
21 Correct 217 ms 1620 KB Output is correct
22 Correct 212 ms 1620 KB Output is correct
23 Correct 183 ms 1632 KB Output is correct
24 Correct 210 ms 1616 KB Output is correct
25 Correct 209 ms 1628 KB Output is correct
26 Correct 402 ms 1916 KB Output is correct
27 Correct 421 ms 1624 KB Output is correct
28 Correct 434 ms 1672 KB Output is correct
29 Correct 414 ms 1624 KB Output is correct
30 Correct 22 ms 1372 KB Output is correct
31 Correct 22 ms 1372 KB Output is correct
32 Correct 24 ms 1368 KB Output is correct
33 Correct 23 ms 1588 KB Output is correct
34 Correct 23 ms 1624 KB Output is correct
35 Correct 23 ms 1372 KB Output is correct
36 Correct 22 ms 1584 KB Output is correct
37 Correct 22 ms 1592 KB Output is correct
38 Correct 23 ms 1368 KB Output is correct
39 Correct 9 ms 1372 KB Output is correct
40 Correct 8 ms 1368 KB Output is correct
41 Correct 8 ms 1368 KB Output is correct
42 Correct 9 ms 1372 KB Output is correct
43 Correct 9 ms 1500 KB Output is correct
44 Correct 15 ms 1368 KB Output is correct
45 Correct 14 ms 1512 KB Output is correct
46 Correct 16 ms 1372 KB Output is correct
47 Correct 17 ms 1508 KB Output is correct
48 Correct 15 ms 1372 KB Output is correct
49 Correct 9 ms 1372 KB Output is correct
50 Correct 7 ms 1372 KB Output is correct
51 Correct 8 ms 1496 KB Output is correct
52 Correct 9 ms 1368 KB Output is correct
53 Correct 9 ms 1372 KB Output is correct
54 Correct 5 ms 1372 KB Output is correct
55 Correct 5 ms 1372 KB Output is correct
56 Correct 6 ms 1624 KB Output is correct
57 Correct 5 ms 1372 KB Output is correct
58 Correct 5 ms 1372 KB Output is correct
59 Correct 524 ms 1652 KB Output is correct
60 Correct 465 ms 1624 KB Output is correct
61 Correct 449 ms 1896 KB Output is correct
62 Correct 571 ms 1628 KB Output is correct
63 Correct 503 ms 1628 KB Output is correct
64 Correct 1186 ms 1696 KB Output is correct
65 Correct 1122 ms 1680 KB Output is correct
66 Correct 1132 ms 1628 KB Output is correct
67 Correct 1156 ms 1628 KB Output is correct
68 Correct 1133 ms 1872 KB Output is correct
69 Correct 446 ms 1628 KB Output is correct
70 Correct 454 ms 1620 KB Output is correct
71 Correct 476 ms 1624 KB Output is correct
72 Correct 499 ms 1668 KB Output is correct
73 Correct 509 ms 1628 KB Output is correct
74 Correct 70 ms 1568 KB Output is correct
75 Correct 63 ms 1372 KB Output is correct
76 Correct 65 ms 1572 KB Output is correct
77 Correct 68 ms 1368 KB Output is correct
78 Correct 68 ms 1372 KB Output is correct