답안 #242886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242886 2020-06-29T16:29:14 Z Redhood Boat (APIO16_boat) C++14
100 / 100
1546 ms 13476 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define mkp make_pair
#define pb push_back
#define len(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
//#define int long long
const int MOD = (int)1e9 + 7, N = 502;
int pw(int a , int b){
    if(b == 0)return 1;
    int ans = pw(a , b >> 1);
    ans = (1ll * ans * ans) % MOD;
    if(b & 1)
        ans = (1ll * ans * a) % MOD;
    return ans;
}
int f[4*N][N] , inv[N] , fact[N];
int C[N][N] , done[4*N][N] , cnt[4*N][N];
void mDD(ll &a){
    if(a >= 1ll*MOD*MOD)
        a-=1ll*MOD*MOD;
}
void md(int &a){
    if(a >= MOD)a-=MOD;
}

void COMBA(vector<pii>&lines){
    fact[0] = 1;
    for(int i = 1 ; i < N; ++i)
        fact[i] = (1ll * fact[i-1] * i) % MOD;

    inv[N-1] = pw(fact[N-1], MOD-2);

    for(int i = N-2;i>=0;--i)
        inv[i] = (1ll * inv[i+1]*(i+1))%MOD;

    for(int i = 0 ; i < N; ++i){
        C[i][0] = 1;
        for(int j = 1; j <= i ; ++j){
            C[i][j] = C[i-1][j] + C[i-1][j-1];
            md(C[i][j]);
        }
    }
    /// fucking cnt[i][j]

    for(int i = 1; i < len(lines); ++i){
        for(int want = 0 ;want < N; ++want){
            int len = lines[i].se - lines[i].fi + 1;
            if(len < want)
                done[i][want] = 0;
            else{
                ll answer = 1;
                for(int j = len-want + 1; j<= len; ++j){
                    answer = (1ll * answer * j) % MOD;
                }
                answer = (1ll * answer * inv[want]) % MOD;
                done[i][want] = answer;
            }
        }
    }
    for(int i = 0 ; i  < len(lines); ++i){
        for(int j = 1 ; j < N; ++j){
            ll CNT = 0;
            for(int k = 0 ; k < j; ++k){
                CNT += (1ll * C[j-1][k] * done[i][j-k]);
                mDD(CNT);
            }
            cnt[i][j] = CNT%MOD;
        }
    }
}
signed main(){
//    ifstream cin("1_01.in");
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n;cin >> n;
    vector<pii>boats(n);
    for(auto&i:boats)cin>>i.fi>>i.se;
    /// lulz wtf is going on here
    set < int > dots;
    for(auto x : boats)
        dots.insert(x.fi) , dots.insert(x.se);
    vector<pii>lines;
    lines.pb({0 , 0});
    for(auto i : dots)
        lines.pb(mkp(i , i));
    auto it = dots.begin();
    int prev = *it;
    ++it;
    while(it != dots.end()){
        if(prev + 1 <= *it-1)
            lines.pb({prev + 1 , *it-1});
        prev = *it;
        ++it;
    }
    sort(all(lines));

    for(auto &i : boats){
        int l = lower_bound(all(lines) , mkp(i.fi , -1))-lines.begin();
        int r = lower_bound(all(lines) , mkp(i.se + 1 , -1))-lines.begin() - 1;
        i = mkp(l , r);
    }

    COMBA(lines);


    for(int i = 0 ; i < n; ++i)
        f[0][i] = 1;
    for(int i = 1; i < len(lines); ++i){
        for(int j = 0; j < N; ++j)
            f[i][j] = f[i-1][j];
        /// what if we skip anybody
        for(int j = 1; j <= n; ++j){
            int cur = j;
            int bad = 0;
            ll DP=0;
            for(int k = 1; k <= n , cur>0; ++k , --cur){
                if(boats[cur-1].se < i || boats[cur-1].fi > i)
                    {bad++;continue;}
                /// firstly update answer
                DP += f[i-1][j-k]*1ll*cnt[i][k - bad];
                mDD(DP);
            }
            f[i][j] += DP%MOD;
            md(f[i][j]);
        }
//        cout << " I " << i << '\n';
//        for(int j = 0 ; j <= n; ++j)
//            cout << f[i][j] << ' ' ;
//        cout << '\n';
    }




    cout << f[len(lines)-1][n];
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:123:30: warning: left operand of comma operator has no effect [-Wunused-value]
             for(int k = 1; k <= n , cur>0; ++k , --cur){
                            ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 783 ms 7416 KB Output is correct
2 Correct 783 ms 7416 KB Output is correct
3 Correct 784 ms 7544 KB Output is correct
4 Correct 791 ms 7288 KB Output is correct
5 Correct 796 ms 7340 KB Output is correct
6 Correct 688 ms 7304 KB Output is correct
7 Correct 678 ms 7288 KB Output is correct
8 Correct 686 ms 7292 KB Output is correct
9 Correct 685 ms 7416 KB Output is correct
10 Correct 720 ms 7352 KB Output is correct
11 Correct 707 ms 7288 KB Output is correct
12 Correct 679 ms 7288 KB Output is correct
13 Correct 677 ms 7440 KB Output is correct
14 Correct 676 ms 7288 KB Output is correct
15 Correct 686 ms 7416 KB Output is correct
16 Correct 138 ms 2424 KB Output is correct
17 Correct 150 ms 2552 KB Output is correct
18 Correct 142 ms 2424 KB Output is correct
19 Correct 149 ms 2552 KB Output is correct
20 Correct 146 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 783 ms 7416 KB Output is correct
2 Correct 783 ms 7416 KB Output is correct
3 Correct 784 ms 7544 KB Output is correct
4 Correct 791 ms 7288 KB Output is correct
5 Correct 796 ms 7340 KB Output is correct
6 Correct 688 ms 7304 KB Output is correct
7 Correct 678 ms 7288 KB Output is correct
8 Correct 686 ms 7292 KB Output is correct
9 Correct 685 ms 7416 KB Output is correct
10 Correct 720 ms 7352 KB Output is correct
11 Correct 707 ms 7288 KB Output is correct
12 Correct 679 ms 7288 KB Output is correct
13 Correct 677 ms 7440 KB Output is correct
14 Correct 676 ms 7288 KB Output is correct
15 Correct 686 ms 7416 KB Output is correct
16 Correct 138 ms 2424 KB Output is correct
17 Correct 150 ms 2552 KB Output is correct
18 Correct 142 ms 2424 KB Output is correct
19 Correct 149 ms 2552 KB Output is correct
20 Correct 146 ms 2424 KB Output is correct
21 Correct 825 ms 11244 KB Output is correct
22 Correct 821 ms 11452 KB Output is correct
23 Correct 803 ms 11256 KB Output is correct
24 Correct 820 ms 11348 KB Output is correct
25 Correct 799 ms 11256 KB Output is correct
26 Correct 730 ms 10744 KB Output is correct
27 Correct 749 ms 10872 KB Output is correct
28 Correct 750 ms 10744 KB Output is correct
29 Correct 747 ms 10872 KB Output is correct
30 Correct 996 ms 12536 KB Output is correct
31 Correct 972 ms 12336 KB Output is correct
32 Correct 1006 ms 12416 KB Output is correct
33 Correct 975 ms 12272 KB Output is correct
34 Correct 987 ms 12540 KB Output is correct
35 Correct 747 ms 7288 KB Output is correct
36 Correct 745 ms 7424 KB Output is correct
37 Correct 764 ms 7520 KB Output is correct
38 Correct 738 ms 7344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 3704 KB Output is correct
2 Correct 211 ms 3832 KB Output is correct
3 Correct 214 ms 3704 KB Output is correct
4 Correct 211 ms 3708 KB Output is correct
5 Correct 213 ms 3704 KB Output is correct
6 Correct 214 ms 3708 KB Output is correct
7 Correct 211 ms 3704 KB Output is correct
8 Correct 210 ms 3832 KB Output is correct
9 Correct 213 ms 3704 KB Output is correct
10 Correct 210 ms 3792 KB Output is correct
11 Correct 213 ms 3704 KB Output is correct
12 Correct 211 ms 3704 KB Output is correct
13 Correct 211 ms 3832 KB Output is correct
14 Correct 211 ms 3704 KB Output is correct
15 Correct 211 ms 3704 KB Output is correct
16 Correct 94 ms 2424 KB Output is correct
17 Correct 95 ms 2424 KB Output is correct
18 Correct 94 ms 2424 KB Output is correct
19 Correct 94 ms 2296 KB Output is correct
20 Correct 99 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 783 ms 7416 KB Output is correct
2 Correct 783 ms 7416 KB Output is correct
3 Correct 784 ms 7544 KB Output is correct
4 Correct 791 ms 7288 KB Output is correct
5 Correct 796 ms 7340 KB Output is correct
6 Correct 688 ms 7304 KB Output is correct
7 Correct 678 ms 7288 KB Output is correct
8 Correct 686 ms 7292 KB Output is correct
9 Correct 685 ms 7416 KB Output is correct
10 Correct 720 ms 7352 KB Output is correct
11 Correct 707 ms 7288 KB Output is correct
12 Correct 679 ms 7288 KB Output is correct
13 Correct 677 ms 7440 KB Output is correct
14 Correct 676 ms 7288 KB Output is correct
15 Correct 686 ms 7416 KB Output is correct
16 Correct 138 ms 2424 KB Output is correct
17 Correct 150 ms 2552 KB Output is correct
18 Correct 142 ms 2424 KB Output is correct
19 Correct 149 ms 2552 KB Output is correct
20 Correct 146 ms 2424 KB Output is correct
21 Correct 825 ms 11244 KB Output is correct
22 Correct 821 ms 11452 KB Output is correct
23 Correct 803 ms 11256 KB Output is correct
24 Correct 820 ms 11348 KB Output is correct
25 Correct 799 ms 11256 KB Output is correct
26 Correct 730 ms 10744 KB Output is correct
27 Correct 749 ms 10872 KB Output is correct
28 Correct 750 ms 10744 KB Output is correct
29 Correct 747 ms 10872 KB Output is correct
30 Correct 996 ms 12536 KB Output is correct
31 Correct 972 ms 12336 KB Output is correct
32 Correct 1006 ms 12416 KB Output is correct
33 Correct 975 ms 12272 KB Output is correct
34 Correct 987 ms 12540 KB Output is correct
35 Correct 747 ms 7288 KB Output is correct
36 Correct 745 ms 7424 KB Output is correct
37 Correct 764 ms 7520 KB Output is correct
38 Correct 738 ms 7344 KB Output is correct
39 Correct 213 ms 3704 KB Output is correct
40 Correct 211 ms 3832 KB Output is correct
41 Correct 214 ms 3704 KB Output is correct
42 Correct 211 ms 3708 KB Output is correct
43 Correct 213 ms 3704 KB Output is correct
44 Correct 214 ms 3708 KB Output is correct
45 Correct 211 ms 3704 KB Output is correct
46 Correct 210 ms 3832 KB Output is correct
47 Correct 213 ms 3704 KB Output is correct
48 Correct 210 ms 3792 KB Output is correct
49 Correct 213 ms 3704 KB Output is correct
50 Correct 211 ms 3704 KB Output is correct
51 Correct 211 ms 3832 KB Output is correct
52 Correct 211 ms 3704 KB Output is correct
53 Correct 211 ms 3704 KB Output is correct
54 Correct 94 ms 2424 KB Output is correct
55 Correct 95 ms 2424 KB Output is correct
56 Correct 94 ms 2424 KB Output is correct
57 Correct 94 ms 2296 KB Output is correct
58 Correct 99 ms 2432 KB Output is correct
59 Correct 1538 ms 13240 KB Output is correct
60 Correct 1539 ms 13176 KB Output is correct
61 Correct 1528 ms 13180 KB Output is correct
62 Correct 1546 ms 13416 KB Output is correct
63 Correct 1530 ms 13176 KB Output is correct
64 Correct 1522 ms 13304 KB Output is correct
65 Correct 1502 ms 13280 KB Output is correct
66 Correct 1491 ms 13176 KB Output is correct
67 Correct 1507 ms 13240 KB Output is correct
68 Correct 1511 ms 13476 KB Output is correct
69 Correct 1468 ms 13232 KB Output is correct
70 Correct 1468 ms 13176 KB Output is correct
71 Correct 1463 ms 13304 KB Output is correct
72 Correct 1453 ms 13348 KB Output is correct
73 Correct 1459 ms 13444 KB Output is correct
74 Correct 162 ms 2556 KB Output is correct
75 Correct 160 ms 2584 KB Output is correct
76 Correct 164 ms 2552 KB Output is correct
77 Correct 158 ms 2552 KB Output is correct
78 Correct 160 ms 2552 KB Output is correct