답안 #487453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487453 2021-11-15T15:07:16 Z leaked Boat (APIO16_boat) C++14
100 / 100
1427 ms 7364 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define vec vector
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define fast_iati ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
typedef long long ll;
typedef pair<int,int> pii;
const int M=1e9+7;
const int N=5e2+10;
const int Mx=200+1;
void add(int &a,int b){
    a+=b;
    if(a>=M) a-=M;
    else if(a<0) a+=M;
}
int mult(int a,int b){
    return 1ll*a*b%M;
}
int binpow(int a,int b){
    int ans=1;
    while(b){
        if(b&1) ans=mult(ans,a);
        b>>=1;a=mult(a,a);
    }
    return ans;
}
int inv[N];
int gi(int x){
    if(!inv[x]) inv[x]=binpow(x,M-2);
    return inv[x];
}
int C(int k,int n){
    if(k>n) return 0;
    int ans=1;
    for(int i=n-k+1;i<=n;i++) ans=mult(ans,i);
    for(int i=1;i<=k;i++) ans=mult(ans,gi(i));
    return ans;
}
signed main(){
    fast_iati;
    int tests=1;
    while(tests--){
        int n=200;
        cin>>n;
        vec<int>a(n),b(n);
        vec<int> kek;
        for(int i=0;i<n;i++) {
            cin>>a[i]>>b[i];
//            a[i]=rand()%Mx+1,b[i]=rand()%Mx+1;
//            if(a[i]>b[i]) swap(a[i],b[i]);
            kek.pb(a[i]-1),kek.pb(b[i]);
        }
        vec<int>l,r;l=a;r=b;
        auto solve=[&](){
            kek.pb(0);sort(all(kek));kek.erase(unique(all(kek)),kek.end());
            vec<vec<int>>dp(n+1,vec<int>(sz(kek)+1,0));
            vec<vec<int>>pref(n+1,vec<int>(sz(kek)+1,0));
            vec<int>ways(sz(kek));
            vec<vec<int>>col(sz(kek),vec<int>(n+1,0));
            vec<vec<int>>cnk(n+1,vec<int>(n+1,0));
            cnk[0][0]=1;
            for(int i=1;i<=n;i++){
                for(int j=0;j<=i;j++){
                    cnk[i][j]=cnk[i-1][j];
                    if(j)
                        add(cnk[i][j],cnk[i-1][j-1]);
                }
            }
            for(int i=1;i<sz(kek);i++){
                ways[i]=kek[i]-kek[i-1];
                vec<int> ct(n+1,0);
                ct[0]=1;
                for(int j=1;j<=n;j++){
                    if(j>ways[i]) ct[j]=0;
                    else{
                        ct[j]=mult(ct[j-1],ways[i]-j+1);
                        ct[j]=mult(ct[j],gi(j));
                    }
//                    cout<<"DEBUGFGEEGEGE"<<"C "<<j<<' '<<ways[i]<<' '<<ct[j]<<' '<<endl;
                }
                /// so
                col[i][2]=ct[2];
//                cout<<ct[2]<<endl;
//                cout<<endl;
//                cout<<"YEA "<<ways[]
                for(int j=3;j<=n;j++){
//                    col[i][j]=col[i][j-1];
//                    col[i][j]=mult(col[i][j],j-2);
//                    add(col[i][j],ct[j]);
                    int fuck=0;
                    for(int t=2;t<=j;t++){
                        add(col[i][j],mult(ct[t],cnk[j-2][t-2]));
//                        cout<<"SHE "<<mult(C(t,ways[i]),C(t-2,j-2))<<endl;
                    }

//                    cout<<"DEBIL "<<ways[i]<<' '<<j<<' '<<col[i][j]<<' '<<fuck<<endl;
                }
//                cout<<endl;
            }
            for(int j=0;j<sz(kek);j++) pref[0][j]=1;
            for(int i=0;i<n;i++){
                a[i]=lower_bound(all(kek),a[i]-1)-kek.begin()+1;
                b[i]=lower_bound(all(kek),b[i])-kek.begin();
            }
            for(int i=0;i<n;i++){
                for(int j=a[i];j<=b[i];j++){
                    /// I start with me
                    /// then it's pref[i][j-1]
                    add(dp[i+1][j],mult(ways[j],pref[i][j-1]));
//                    if(i==1)cout<<"ALO "<<pref[i][j-1]<<endl;
                    if(ways[j]>=2){
                        int cnt=1;
                        for(int k=i-1;k>=0;k--){
                            if(a[k]>j || b[k]<j) continue;
                            cnt++;
//                            cout<<"CHECK "<<i<<' '<<k<<' '<<j<<' '<<' '<<col[j][cnt]<<' '<<pref[k][j-1]<<endl;
                            add(dp[i+1][j],mult(col[j][cnt],pref[k][j-1]));
                        }
                    }
                }
//                 for(int j=0;j<sz(kek);j++){
//                    cout<<"DEBUG "<<(j?kek[j-1]+1:0)<<' '<<kek[j]<<' '<<dp[i+1][j]<<endl;
//                }
//                cout<<endl;
                for(int j=0;j<sz(kek);j++){
                    pref[i+1][j]=dp[i+1][j];
                    if(j)add(pref[i+1][j],pref[i+1][j-1]);
                }
                for(int j=0;j<sz(kek);j++){
                    add(pref[i+1][j],pref[i][j]);
                }
            }
            return pref[n][sz(kek)-1];
        };
        auto stupid=[&](){
            vec<vec<int>>dp1(n+1,vec<int>(Mx+1,0));
            for(int j=0;j<=Mx;j++) dp1[0][j]=1;
            for(int i=0;i<n;i++){
//                cout<<"AUE "<<l[i]<<' '<<r[i]<<endl;
                for(int x=l[i];x<=r[i];x++){
                    add(dp1[i+1][x],dp1[i][x-1]);
                }
                for(int j=1;j<=Mx;j++)add(dp1[i+1][j],dp1[i+1][j-1]);
//                cout<<endl;
                for(int j=0;j<=Mx;j++){
                    add(dp1[i+1][j],dp1[i][j]);
                }
            }
            return dp1[n][Mx];
        };
        int rans=solve();
        add(rans,-1);
        cout<<rans;
//        cout<<"SOL "<<stupid()<<' '<<solve()<<endl;
//        int x=solve(),y=stupid();
//        if(x!=y){
//            cout<<y<<' '<<x<<endl;
//            cout<<n<<endl;
//            for(int i=0;i<n;i++) cout<<l[i]<<' '<<r[i]<<endl;
//            return 0;
//        }
    }
    return 0;
}

Compilation message

boat.cpp: In lambda function:
boat.cpp:102:25: warning: unused variable 'fuck' [-Wunused-variable]
  102 |                     int fuck=0;
      |                         ^~~~
boat.cpp: In function 'int main()':
boat.cpp:147:14: warning: variable 'stupid' set but not used [-Wunused-but-set-variable]
  147 |         auto stupid=[&](){
      |              ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 746 ms 7276 KB Output is correct
2 Correct 771 ms 7272 KB Output is correct
3 Correct 792 ms 7268 KB Output is correct
4 Correct 727 ms 7268 KB Output is correct
5 Correct 790 ms 7276 KB Output is correct
6 Correct 721 ms 7276 KB Output is correct
7 Correct 751 ms 7272 KB Output is correct
8 Correct 701 ms 7272 KB Output is correct
9 Correct 716 ms 7272 KB Output is correct
10 Correct 720 ms 7364 KB Output is correct
11 Correct 735 ms 7276 KB Output is correct
12 Correct 775 ms 7276 KB Output is correct
13 Correct 729 ms 7272 KB Output is correct
14 Correct 772 ms 7276 KB Output is correct
15 Correct 736 ms 7272 KB Output is correct
16 Correct 131 ms 2420 KB Output is correct
17 Correct 144 ms 2508 KB Output is correct
18 Correct 128 ms 2380 KB Output is correct
19 Correct 136 ms 2484 KB Output is correct
20 Correct 141 ms 2440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 746 ms 7276 KB Output is correct
2 Correct 771 ms 7272 KB Output is correct
3 Correct 792 ms 7268 KB Output is correct
4 Correct 727 ms 7268 KB Output is correct
5 Correct 790 ms 7276 KB Output is correct
6 Correct 721 ms 7276 KB Output is correct
7 Correct 751 ms 7272 KB Output is correct
8 Correct 701 ms 7272 KB Output is correct
9 Correct 716 ms 7272 KB Output is correct
10 Correct 720 ms 7364 KB Output is correct
11 Correct 735 ms 7276 KB Output is correct
12 Correct 775 ms 7276 KB Output is correct
13 Correct 729 ms 7272 KB Output is correct
14 Correct 772 ms 7276 KB Output is correct
15 Correct 736 ms 7272 KB Output is correct
16 Correct 131 ms 2420 KB Output is correct
17 Correct 144 ms 2508 KB Output is correct
18 Correct 128 ms 2380 KB Output is correct
19 Correct 136 ms 2484 KB Output is correct
20 Correct 141 ms 2440 KB Output is correct
21 Correct 679 ms 6748 KB Output is correct
22 Correct 674 ms 6836 KB Output is correct
23 Correct 632 ms 6736 KB Output is correct
24 Correct 663 ms 6696 KB Output is correct
25 Correct 654 ms 6720 KB Output is correct
26 Correct 673 ms 6576 KB Output is correct
27 Correct 670 ms 6672 KB Output is correct
28 Correct 692 ms 6572 KB Output is correct
29 Correct 687 ms 6544 KB Output is correct
30 Correct 703 ms 7288 KB Output is correct
31 Correct 707 ms 7288 KB Output is correct
32 Correct 702 ms 7284 KB Output is correct
33 Correct 733 ms 7284 KB Output is correct
34 Correct 741 ms 7260 KB Output is correct
35 Correct 699 ms 7248 KB Output is correct
36 Correct 715 ms 7196 KB Output is correct
37 Correct 690 ms 7280 KB Output is correct
38 Correct 683 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 616 KB Output is correct
2 Correct 26 ms 620 KB Output is correct
3 Correct 10 ms 616 KB Output is correct
4 Correct 11 ms 616 KB Output is correct
5 Correct 11 ms 592 KB Output is correct
6 Correct 14 ms 604 KB Output is correct
7 Correct 13 ms 620 KB Output is correct
8 Correct 12 ms 624 KB Output is correct
9 Correct 13 ms 624 KB Output is correct
10 Correct 13 ms 620 KB Output is correct
11 Correct 13 ms 636 KB Output is correct
12 Correct 12 ms 620 KB Output is correct
13 Correct 12 ms 620 KB Output is correct
14 Correct 11 ms 620 KB Output is correct
15 Correct 13 ms 616 KB Output is correct
16 Correct 7 ms 464 KB Output is correct
17 Correct 6 ms 464 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 464 KB Output is correct
20 Correct 6 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 746 ms 7276 KB Output is correct
2 Correct 771 ms 7272 KB Output is correct
3 Correct 792 ms 7268 KB Output is correct
4 Correct 727 ms 7268 KB Output is correct
5 Correct 790 ms 7276 KB Output is correct
6 Correct 721 ms 7276 KB Output is correct
7 Correct 751 ms 7272 KB Output is correct
8 Correct 701 ms 7272 KB Output is correct
9 Correct 716 ms 7272 KB Output is correct
10 Correct 720 ms 7364 KB Output is correct
11 Correct 735 ms 7276 KB Output is correct
12 Correct 775 ms 7276 KB Output is correct
13 Correct 729 ms 7272 KB Output is correct
14 Correct 772 ms 7276 KB Output is correct
15 Correct 736 ms 7272 KB Output is correct
16 Correct 131 ms 2420 KB Output is correct
17 Correct 144 ms 2508 KB Output is correct
18 Correct 128 ms 2380 KB Output is correct
19 Correct 136 ms 2484 KB Output is correct
20 Correct 141 ms 2440 KB Output is correct
21 Correct 679 ms 6748 KB Output is correct
22 Correct 674 ms 6836 KB Output is correct
23 Correct 632 ms 6736 KB Output is correct
24 Correct 663 ms 6696 KB Output is correct
25 Correct 654 ms 6720 KB Output is correct
26 Correct 673 ms 6576 KB Output is correct
27 Correct 670 ms 6672 KB Output is correct
28 Correct 692 ms 6572 KB Output is correct
29 Correct 687 ms 6544 KB Output is correct
30 Correct 703 ms 7288 KB Output is correct
31 Correct 707 ms 7288 KB Output is correct
32 Correct 702 ms 7284 KB Output is correct
33 Correct 733 ms 7284 KB Output is correct
34 Correct 741 ms 7260 KB Output is correct
35 Correct 699 ms 7248 KB Output is correct
36 Correct 715 ms 7196 KB Output is correct
37 Correct 690 ms 7280 KB Output is correct
38 Correct 683 ms 7248 KB Output is correct
39 Correct 11 ms 616 KB Output is correct
40 Correct 26 ms 620 KB Output is correct
41 Correct 10 ms 616 KB Output is correct
42 Correct 11 ms 616 KB Output is correct
43 Correct 11 ms 592 KB Output is correct
44 Correct 14 ms 604 KB Output is correct
45 Correct 13 ms 620 KB Output is correct
46 Correct 12 ms 624 KB Output is correct
47 Correct 13 ms 624 KB Output is correct
48 Correct 13 ms 620 KB Output is correct
49 Correct 13 ms 636 KB Output is correct
50 Correct 12 ms 620 KB Output is correct
51 Correct 12 ms 620 KB Output is correct
52 Correct 11 ms 620 KB Output is correct
53 Correct 13 ms 616 KB Output is correct
54 Correct 7 ms 464 KB Output is correct
55 Correct 6 ms 464 KB Output is correct
56 Correct 6 ms 512 KB Output is correct
57 Correct 6 ms 464 KB Output is correct
58 Correct 6 ms 508 KB Output is correct
59 Correct 1347 ms 7288 KB Output is correct
60 Correct 1275 ms 7284 KB Output is correct
61 Correct 1268 ms 7304 KB Output is correct
62 Correct 1326 ms 7284 KB Output is correct
63 Correct 1256 ms 7284 KB Output is correct
64 Correct 1357 ms 7292 KB Output is correct
65 Correct 1427 ms 7284 KB Output is correct
66 Correct 1402 ms 7288 KB Output is correct
67 Correct 1384 ms 7292 KB Output is correct
68 Correct 1336 ms 7292 KB Output is correct
69 Correct 1206 ms 7288 KB Output is correct
70 Correct 1176 ms 7288 KB Output is correct
71 Correct 1196 ms 7284 KB Output is correct
72 Correct 1304 ms 7280 KB Output is correct
73 Correct 1143 ms 7248 KB Output is correct
74 Correct 161 ms 2440 KB Output is correct
75 Correct 162 ms 2480 KB Output is correct
76 Correct 161 ms 2504 KB Output is correct
77 Correct 167 ms 2448 KB Output is correct
78 Correct 168 ms 2432 KB Output is correct