답안 #970709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970709 2024-04-27T06:40:59 Z VinhLuu Boat (APIO16_boat) C++17
100 / 100
491 ms 8792 KB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()

using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1005;
int block = 555;
const int mod = 1e9 + 7;
//const ll oo = 5e18;

int n, L[N], R[N];
ll f[N][N], inv[N];

ll lt(ll u,ll v){
    if(v == 0) return 1;
    ll x = u, kq = 1;
    while(v){
        if(v & 1) kq = kq * x % mod;
        x = x * x % mod;
        v /= 2;
    }
    return kq;
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }

    cin >> n;
    vector<int> rrh;
    for(int i = 1; i <= n; i ++){
        cin >> L[i] >> R[i];
        rrh.pb(L[i]);
        rrh.pb(R[i] + 1);
    }
    sort(all(rrh)); rrh.resize(unique(all(rrh)) - rrh.begin());


    inv[0] = f[0][0] = 1;
    for(int i = 1; i <= n + 1; i ++) inv[i] = lt(i, mod - 2);

    for(int i = 1; i < rrh.size(); i ++){
//        cerr << i << " h\n";
        f[i][0] = 1;
        for(int j = 1; j <= n; j ++) if(L[j] <= rrh[i - 1] && rrh[i - 1] <= R[j]){
            f[i][j] = f[i - 1][j];
            ll w = rrh[i] - rrh[i - 1], pick = 1, cnt = 0;
//            cerr << i << " " << j << " " << f[i][j] << " j\n";
            for(int k = 1; k <= j; k ++){
                if(L[j - k + 1] <= rrh[i - 1] && rrh[i - 1] <= R[j - k + 1]){
//                    if(cnt + 1 <= w){
                        cnt++;
                        pick = pick * (w + cnt - 1) % mod * inv[cnt] % mod;
//                        if(cnt == 1) pick = pick * (w - cnt + 1) % mod * inv[cnt] % mod;
//                        else pick = (pick + pick * (w - cnt + 1) % mod * inv[cnt] % mod) % mod;
//                    }else pick = (pick +  0ll * cnt * pick % mod) % mod;
//                    cerr << i << " " << w << " " << k << " " << j - k << " " << pick << " " << f[i - 1][j - k] << " g\n";
                    f[i][j] = (f[i][j] + f[i - 1][j - k] * pick % mod) % mod;
                }else{
                    f[i][j] = (f[i][j] + f[i - 1][j - k] * pick % mod) % mod;
                }
            }
//            cerr << i << " " << j << " " << f[i][j] << " k\n";
        }else{
            f[i][j] = f[i - 1][j];
//            cerr << i << " " << j << " " << f[i][j] << " k\n";
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i ++) ans = (ans + f[rrh.size() - 1][i]) % mod;
    cout << ans;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 1; i < rrh.size(); i ++){
      |                    ~~^~~~~~~~~~~~
boat.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8352 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 3 ms 8148 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 4 ms 8536 KB Output is correct
9 Correct 3 ms 8792 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8344 KB Output is correct
12 Correct 3 ms 8280 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 3 ms 8352 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8352 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 3 ms 8148 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 4 ms 8536 KB Output is correct
9 Correct 3 ms 8792 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8344 KB Output is correct
12 Correct 3 ms 8280 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 3 ms 8352 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 228 ms 7548 KB Output is correct
22 Correct 214 ms 7556 KB Output is correct
23 Correct 194 ms 7508 KB Output is correct
24 Correct 217 ms 7508 KB Output is correct
25 Correct 213 ms 7556 KB Output is correct
26 Correct 423 ms 7552 KB Output is correct
27 Correct 432 ms 7296 KB Output is correct
28 Correct 422 ms 7504 KB Output is correct
29 Correct 414 ms 7304 KB Output is correct
30 Correct 4 ms 8280 KB Output is correct
31 Correct 5 ms 8284 KB Output is correct
32 Correct 4 ms 8284 KB Output is correct
33 Correct 4 ms 8284 KB Output is correct
34 Correct 4 ms 8152 KB Output is correct
35 Correct 4 ms 8284 KB Output is correct
36 Correct 4 ms 8284 KB Output is correct
37 Correct 4 ms 8284 KB Output is correct
38 Correct 4 ms 8092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 3 ms 2392 KB Output is correct
3 Correct 2 ms 2392 KB Output is correct
4 Correct 3 ms 2392 KB Output is correct
5 Correct 3 ms 2392 KB Output is correct
6 Correct 4 ms 2396 KB Output is correct
7 Correct 4 ms 2516 KB Output is correct
8 Correct 4 ms 2396 KB Output is correct
9 Correct 5 ms 2396 KB Output is correct
10 Correct 4 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 2 ms 2400 KB Output is correct
15 Correct 3 ms 2400 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2660 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 2 ms 2400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8352 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 3 ms 8148 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 4 ms 8536 KB Output is correct
9 Correct 3 ms 8792 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8344 KB Output is correct
12 Correct 3 ms 8280 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 3 ms 8352 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 228 ms 7548 KB Output is correct
22 Correct 214 ms 7556 KB Output is correct
23 Correct 194 ms 7508 KB Output is correct
24 Correct 217 ms 7508 KB Output is correct
25 Correct 213 ms 7556 KB Output is correct
26 Correct 423 ms 7552 KB Output is correct
27 Correct 432 ms 7296 KB Output is correct
28 Correct 422 ms 7504 KB Output is correct
29 Correct 414 ms 7304 KB Output is correct
30 Correct 4 ms 8280 KB Output is correct
31 Correct 5 ms 8284 KB Output is correct
32 Correct 4 ms 8284 KB Output is correct
33 Correct 4 ms 8284 KB Output is correct
34 Correct 4 ms 8152 KB Output is correct
35 Correct 4 ms 8284 KB Output is correct
36 Correct 4 ms 8284 KB Output is correct
37 Correct 4 ms 8284 KB Output is correct
38 Correct 4 ms 8092 KB Output is correct
39 Correct 3 ms 2392 KB Output is correct
40 Correct 3 ms 2392 KB Output is correct
41 Correct 2 ms 2392 KB Output is correct
42 Correct 3 ms 2392 KB Output is correct
43 Correct 3 ms 2392 KB Output is correct
44 Correct 4 ms 2396 KB Output is correct
45 Correct 4 ms 2516 KB Output is correct
46 Correct 4 ms 2396 KB Output is correct
47 Correct 5 ms 2396 KB Output is correct
48 Correct 4 ms 2396 KB Output is correct
49 Correct 3 ms 2396 KB Output is correct
50 Correct 2 ms 2636 KB Output is correct
51 Correct 2 ms 2392 KB Output is correct
52 Correct 2 ms 2400 KB Output is correct
53 Correct 3 ms 2400 KB Output is correct
54 Correct 2 ms 2396 KB Output is correct
55 Correct 2 ms 2396 KB Output is correct
56 Correct 2 ms 2660 KB Output is correct
57 Correct 2 ms 2396 KB Output is correct
58 Correct 2 ms 2400 KB Output is correct
59 Correct 240 ms 8284 KB Output is correct
60 Correct 226 ms 8276 KB Output is correct
61 Correct 212 ms 8376 KB Output is correct
62 Correct 245 ms 8320 KB Output is correct
63 Correct 241 ms 8328 KB Output is correct
64 Correct 491 ms 8328 KB Output is correct
65 Correct 484 ms 8244 KB Output is correct
66 Correct 480 ms 8276 KB Output is correct
67 Correct 483 ms 8220 KB Output is correct
68 Correct 482 ms 8328 KB Output is correct
69 Correct 196 ms 8276 KB Output is correct
70 Correct 195 ms 8280 KB Output is correct
71 Correct 198 ms 8324 KB Output is correct
72 Correct 203 ms 8324 KB Output is correct
73 Correct 207 ms 8272 KB Output is correct
74 Correct 48 ms 2688 KB Output is correct
75 Correct 47 ms 2652 KB Output is correct
76 Correct 48 ms 2652 KB Output is correct
77 Correct 47 ms 2652 KB Output is correct
78 Correct 48 ms 2652 KB Output is correct