답안 #1092809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092809 2024-09-25T07:38:03 Z alexander707070 Boat (APIO16_boat) C++14
9 / 100
15 ms 12120 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#define MAXN 1507
using namespace std;

struct group{
    int from,to;
}s[2*MAXN];

const long long mod=1e9+7;

int n,a[MAXN],b[MAXN],m;
vector<int> pos;

bool in(group g,int id){
    return g.from>=a[id] and g.to<=b[id];
}

long long dp[MAXN][MAXN][2];
long long invfact[MAXN];

long long comb(int x,int g){

    long long res=1,sz=s[g].to-s[g].from+1;

    for(long long i=sz;i>=sz-x+1;i--){
        res*=i; res%=mod;
    }

    res*=invfact[x]; res%=mod;
    return res;
}

long long power(long long a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b==2)return (a*a)%mod;
    if(b%2==0)return power(power(a,b/2),2);
    return (a*power(power(a,b/2),2));
}


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];

        pos.push_back(a[i]);
        pos.push_back(b[i]);
    }

    invfact[0]=1;
    for(int i=1;i<=n;i++)invfact[i]=(invfact[i-1]*i)%mod;
    for(int i=1;i<=n;i++)invfact[i]=power(invfact[i],mod-2);

    sort(pos.begin(),pos.end());
    
    for(int i=0;i<pos.size()-1;i++){
        if(pos[i]!=pos[i+1]){
            m++; s[m]={pos[i],pos[i]};
            
            if(pos[i]+1<=pos[i+1]-1){
                m++; s[m]={pos[i]+1,pos[i+1]-1};
            }
        }
    }

    m++;
    s[m]={pos.back(),pos.back()};

    for(int i=0;i<=n;i++)dp[i][0][1]=1;
    for(int i=0;i<=m;i++)dp[0][i][1]=1;

    for(int i=1;i<=n;i++){
        for(int f=1;f<=m;f++){
            for(int t=0;t<2;t++){
                
                dp[i][f][t]=dp[i-1][f][0];
                if(t==1)dp[i][f][t]+=dp[i][f-1][1];

                for(int k=i;k>=1 and i-k+1<=s[f].to-s[f].from+1;k--){
                    if(!in(s[f],k))break;

                    dp[i][f][t]+=(dp[k-1][f-1][1]*comb(i-k+1,f))%mod;
                }

                dp[i][f][t]%=mod;
            }
        }
    }

    cout<<dp[n][m][1]-1<<"\n";
 
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for(int i=0;i<pos.size()-1;i++){
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10332 KB Output is correct
2 Correct 7 ms 10332 KB Output is correct
3 Correct 6 ms 10200 KB Output is correct
4 Correct 7 ms 10132 KB Output is correct
5 Correct 7 ms 10328 KB Output is correct
6 Correct 7 ms 10328 KB Output is correct
7 Correct 7 ms 10332 KB Output is correct
8 Correct 7 ms 10188 KB Output is correct
9 Correct 7 ms 10332 KB Output is correct
10 Correct 7 ms 10332 KB Output is correct
11 Correct 10 ms 10332 KB Output is correct
12 Correct 8 ms 10332 KB Output is correct
13 Correct 7 ms 10148 KB Output is correct
14 Correct 7 ms 10332 KB Output is correct
15 Correct 6 ms 10332 KB Output is correct
16 Correct 2 ms 3676 KB Output is correct
17 Correct 2 ms 3896 KB Output is correct
18 Correct 2 ms 3932 KB Output is correct
19 Correct 2 ms 3932 KB Output is correct
20 Correct 2 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10332 KB Output is correct
2 Correct 7 ms 10332 KB Output is correct
3 Correct 6 ms 10200 KB Output is correct
4 Correct 7 ms 10132 KB Output is correct
5 Correct 7 ms 10328 KB Output is correct
6 Correct 7 ms 10328 KB Output is correct
7 Correct 7 ms 10332 KB Output is correct
8 Correct 7 ms 10188 KB Output is correct
9 Correct 7 ms 10332 KB Output is correct
10 Correct 7 ms 10332 KB Output is correct
11 Correct 10 ms 10332 KB Output is correct
12 Correct 8 ms 10332 KB Output is correct
13 Correct 7 ms 10148 KB Output is correct
14 Correct 7 ms 10332 KB Output is correct
15 Correct 6 ms 10332 KB Output is correct
16 Correct 2 ms 3676 KB Output is correct
17 Correct 2 ms 3896 KB Output is correct
18 Correct 2 ms 3932 KB Output is correct
19 Correct 2 ms 3932 KB Output is correct
20 Correct 2 ms 3932 KB Output is correct
21 Incorrect 15 ms 12120 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10332 KB Output is correct
2 Correct 7 ms 10332 KB Output is correct
3 Correct 6 ms 10200 KB Output is correct
4 Correct 7 ms 10132 KB Output is correct
5 Correct 7 ms 10328 KB Output is correct
6 Correct 7 ms 10328 KB Output is correct
7 Correct 7 ms 10332 KB Output is correct
8 Correct 7 ms 10188 KB Output is correct
9 Correct 7 ms 10332 KB Output is correct
10 Correct 7 ms 10332 KB Output is correct
11 Correct 10 ms 10332 KB Output is correct
12 Correct 8 ms 10332 KB Output is correct
13 Correct 7 ms 10148 KB Output is correct
14 Correct 7 ms 10332 KB Output is correct
15 Correct 6 ms 10332 KB Output is correct
16 Correct 2 ms 3676 KB Output is correct
17 Correct 2 ms 3896 KB Output is correct
18 Correct 2 ms 3932 KB Output is correct
19 Correct 2 ms 3932 KB Output is correct
20 Correct 2 ms 3932 KB Output is correct
21 Incorrect 15 ms 12120 KB Output isn't correct
22 Halted 0 ms 0 KB -