Submission #242885

# Submission time Handle Problem Language Result Execution time Memory
242885 2020-06-29T16:27:45 Z Redhood Boat (APIO16_boat) C++14
58 / 100
2000 ms 12420 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 , NN = 1001;
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 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){
            for(int k = 0 ; k < j; ++k){
                cnt[i][j] += (1ll * C[j-1][k] * done[i][j-k])%MOD;
                md(cnt[i][j]);
            }
        }
    }
}
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;
            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
                f[i][j] += (f[i-1][j-k]*1ll*cnt[i][k - bad])%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:117:30: warning: left operand of comma operator has no effect [-Wunused-value]
             for(int k = 1; k <= n , cur>0; ++k , --cur){
                            ~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1053 ms 7392 KB Output is correct
2 Correct 1057 ms 7288 KB Output is correct
3 Correct 1062 ms 7416 KB Output is correct
4 Correct 1058 ms 7312 KB Output is correct
5 Correct 1059 ms 7468 KB Output is correct
6 Correct 967 ms 7416 KB Output is correct
7 Correct 967 ms 7288 KB Output is correct
8 Correct 956 ms 7416 KB Output is correct
9 Correct 965 ms 7516 KB Output is correct
10 Correct 968 ms 7416 KB Output is correct
11 Correct 958 ms 7544 KB Output is correct
12 Correct 973 ms 7288 KB Output is correct
13 Correct 953 ms 7288 KB Output is correct
14 Correct 965 ms 7288 KB Output is correct
15 Correct 961 ms 7288 KB Output is correct
16 Correct 188 ms 2424 KB Output is correct
17 Correct 200 ms 2744 KB Output is correct
18 Correct 192 ms 2424 KB Output is correct
19 Correct 200 ms 2552 KB Output is correct
20 Correct 194 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1053 ms 7392 KB Output is correct
2 Correct 1057 ms 7288 KB Output is correct
3 Correct 1062 ms 7416 KB Output is correct
4 Correct 1058 ms 7312 KB Output is correct
5 Correct 1059 ms 7468 KB Output is correct
6 Correct 967 ms 7416 KB Output is correct
7 Correct 967 ms 7288 KB Output is correct
8 Correct 956 ms 7416 KB Output is correct
9 Correct 965 ms 7516 KB Output is correct
10 Correct 968 ms 7416 KB Output is correct
11 Correct 958 ms 7544 KB Output is correct
12 Correct 973 ms 7288 KB Output is correct
13 Correct 953 ms 7288 KB Output is correct
14 Correct 965 ms 7288 KB Output is correct
15 Correct 961 ms 7288 KB Output is correct
16 Correct 188 ms 2424 KB Output is correct
17 Correct 200 ms 2744 KB Output is correct
18 Correct 192 ms 2424 KB Output is correct
19 Correct 200 ms 2552 KB Output is correct
20 Correct 194 ms 2424 KB Output is correct
21 Correct 1402 ms 11384 KB Output is correct
22 Correct 1411 ms 11256 KB Output is correct
23 Correct 1374 ms 11128 KB Output is correct
24 Correct 1414 ms 11256 KB Output is correct
25 Correct 1397 ms 11136 KB Output is correct
26 Correct 1449 ms 10616 KB Output is correct
27 Correct 1447 ms 10824 KB Output is correct
28 Correct 1441 ms 10656 KB Output is correct
29 Correct 1448 ms 10864 KB Output is correct
30 Correct 1510 ms 12372 KB Output is correct
31 Correct 1498 ms 12420 KB Output is correct
32 Correct 1506 ms 12408 KB Output is correct
33 Correct 1493 ms 12312 KB Output is correct
34 Correct 1495 ms 12388 KB Output is correct
35 Correct 1030 ms 7416 KB Output is correct
36 Correct 1034 ms 7272 KB Output is correct
37 Correct 1041 ms 7336 KB Output is correct
38 Correct 1032 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 3848 KB Output is correct
2 Correct 343 ms 3704 KB Output is correct
3 Correct 346 ms 3764 KB Output is correct
4 Correct 344 ms 3736 KB Output is correct
5 Correct 343 ms 3832 KB Output is correct
6 Correct 347 ms 3704 KB Output is correct
7 Correct 345 ms 3708 KB Output is correct
8 Correct 348 ms 3832 KB Output is correct
9 Correct 344 ms 3704 KB Output is correct
10 Correct 346 ms 3704 KB Output is correct
11 Correct 342 ms 3704 KB Output is correct
12 Correct 347 ms 3872 KB Output is correct
13 Correct 340 ms 3704 KB Output is correct
14 Correct 346 ms 3704 KB Output is correct
15 Correct 345 ms 3704 KB Output is correct
16 Correct 153 ms 2424 KB Output is correct
17 Correct 152 ms 2508 KB Output is correct
18 Correct 152 ms 2424 KB Output is correct
19 Correct 153 ms 2424 KB Output is correct
20 Correct 159 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1053 ms 7392 KB Output is correct
2 Correct 1057 ms 7288 KB Output is correct
3 Correct 1062 ms 7416 KB Output is correct
4 Correct 1058 ms 7312 KB Output is correct
5 Correct 1059 ms 7468 KB Output is correct
6 Correct 967 ms 7416 KB Output is correct
7 Correct 967 ms 7288 KB Output is correct
8 Correct 956 ms 7416 KB Output is correct
9 Correct 965 ms 7516 KB Output is correct
10 Correct 968 ms 7416 KB Output is correct
11 Correct 958 ms 7544 KB Output is correct
12 Correct 973 ms 7288 KB Output is correct
13 Correct 953 ms 7288 KB Output is correct
14 Correct 965 ms 7288 KB Output is correct
15 Correct 961 ms 7288 KB Output is correct
16 Correct 188 ms 2424 KB Output is correct
17 Correct 200 ms 2744 KB Output is correct
18 Correct 192 ms 2424 KB Output is correct
19 Correct 200 ms 2552 KB Output is correct
20 Correct 194 ms 2424 KB Output is correct
21 Correct 1402 ms 11384 KB Output is correct
22 Correct 1411 ms 11256 KB Output is correct
23 Correct 1374 ms 11128 KB Output is correct
24 Correct 1414 ms 11256 KB Output is correct
25 Correct 1397 ms 11136 KB Output is correct
26 Correct 1449 ms 10616 KB Output is correct
27 Correct 1447 ms 10824 KB Output is correct
28 Correct 1441 ms 10656 KB Output is correct
29 Correct 1448 ms 10864 KB Output is correct
30 Correct 1510 ms 12372 KB Output is correct
31 Correct 1498 ms 12420 KB Output is correct
32 Correct 1506 ms 12408 KB Output is correct
33 Correct 1493 ms 12312 KB Output is correct
34 Correct 1495 ms 12388 KB Output is correct
35 Correct 1030 ms 7416 KB Output is correct
36 Correct 1034 ms 7272 KB Output is correct
37 Correct 1041 ms 7336 KB Output is correct
38 Correct 1032 ms 7416 KB Output is correct
39 Correct 346 ms 3848 KB Output is correct
40 Correct 343 ms 3704 KB Output is correct
41 Correct 346 ms 3764 KB Output is correct
42 Correct 344 ms 3736 KB Output is correct
43 Correct 343 ms 3832 KB Output is correct
44 Correct 347 ms 3704 KB Output is correct
45 Correct 345 ms 3708 KB Output is correct
46 Correct 348 ms 3832 KB Output is correct
47 Correct 344 ms 3704 KB Output is correct
48 Correct 346 ms 3704 KB Output is correct
49 Correct 342 ms 3704 KB Output is correct
50 Correct 347 ms 3872 KB Output is correct
51 Correct 340 ms 3704 KB Output is correct
52 Correct 346 ms 3704 KB Output is correct
53 Correct 345 ms 3704 KB Output is correct
54 Correct 153 ms 2424 KB Output is correct
55 Correct 152 ms 2508 KB Output is correct
56 Correct 152 ms 2424 KB Output is correct
57 Correct 153 ms 2424 KB Output is correct
58 Correct 159 ms 2552 KB Output is correct
59 Execution timed out 2082 ms 11716 KB Time limit exceeded
60 Halted 0 ms 0 KB -