답안 #549772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549772 2022-04-16T13:38:49 Z krit3379 Boat (APIO16_boat) C++17
9 / 100
7 ms 4308 KB
#include<bits/stdc++.h>
using namespace std;
#define N 505

long long dp[N][2*N],a[N],b[N],len[2*N],inv[N],cnt,ch,mod=1e9+7;
vector<long long> v;

int main(){
    int n,i,j,k;
    scanf("%d",&n);
    inv[1]=1;
    for(i=2;i<N;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]+1);
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    for(i=1;i<=n;i++){
        a[i]=upper_bound(v.begin(),v.end(),a[i])-v.begin();
        b[i]=upper_bound(v.begin(),v.end(),b[i])-v.begin();
    }
    for(i=1;i<v.size();i++)len[i]=v[i]-v[i-1];
    for(i=0;i<v.size();i++)dp[0][i]=1;
    for(i=1;i<=n;i++){
        for(j=a[i];j<=b[i];j++){
            dp[i][j]=len[j]*dp[i-1][j-1]%mod;
            cnt=1,ch=len[j]-1;
            for(k=i-1;i>0;k--){
                if(a[k]<=j&&j<=b[k]){
                    cnt++;
                    ch=ch*(len[j]+cnt-2)%mod*inv[cnt]%mod;
                    if(!ch)break;
                    dp[i][j]=(dp[i][j]+dp[k-1][j-1]*ch)%mod;
                }
            }
        }
        dp[i][0]=1;
        for(j=1;j<v.size();j++)
            dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
    }
    printf("%lld",(dp[n][v.size()-1]-1+mod)%mod);
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(i=1;i<v.size();i++)len[i]=v[i]-v[i-1];
      |             ~^~~~~~~~~
boat.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(i=0;i<v.size();i++)dp[0][i]=1;
      |             ~^~~~~~~~~
boat.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(j=1;j<v.size();j++)
      |                 ~^~~~~~~~~
boat.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]+1);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4280 KB Output is correct
2 Correct 7 ms 4180 KB Output is correct
3 Correct 7 ms 4308 KB Output is correct
4 Correct 6 ms 4284 KB Output is correct
5 Correct 6 ms 4180 KB Output is correct
6 Correct 5 ms 4284 KB Output is correct
7 Correct 5 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 5 ms 4308 KB Output is correct
10 Correct 5 ms 4180 KB Output is correct
11 Correct 6 ms 4284 KB Output is correct
12 Correct 6 ms 4308 KB Output is correct
13 Correct 6 ms 4308 KB Output is correct
14 Correct 7 ms 4308 KB Output is correct
15 Correct 7 ms 4308 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3004 KB Output is correct
20 Correct 2 ms 2996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4280 KB Output is correct
2 Correct 7 ms 4180 KB Output is correct
3 Correct 7 ms 4308 KB Output is correct
4 Correct 6 ms 4284 KB Output is correct
5 Correct 6 ms 4180 KB Output is correct
6 Correct 5 ms 4284 KB Output is correct
7 Correct 5 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 5 ms 4308 KB Output is correct
10 Correct 5 ms 4180 KB Output is correct
11 Correct 6 ms 4284 KB Output is correct
12 Correct 6 ms 4308 KB Output is correct
13 Correct 6 ms 4308 KB Output is correct
14 Correct 7 ms 4308 KB Output is correct
15 Correct 7 ms 4308 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3004 KB Output is correct
20 Correct 2 ms 2996 KB Output is correct
21 Runtime error 1 ms 468 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4280 KB Output is correct
2 Correct 7 ms 4180 KB Output is correct
3 Correct 7 ms 4308 KB Output is correct
4 Correct 6 ms 4284 KB Output is correct
5 Correct 6 ms 4180 KB Output is correct
6 Correct 5 ms 4284 KB Output is correct
7 Correct 5 ms 4308 KB Output is correct
8 Correct 5 ms 4308 KB Output is correct
9 Correct 5 ms 4308 KB Output is correct
10 Correct 5 ms 4180 KB Output is correct
11 Correct 6 ms 4284 KB Output is correct
12 Correct 6 ms 4308 KB Output is correct
13 Correct 6 ms 4308 KB Output is correct
14 Correct 7 ms 4308 KB Output is correct
15 Correct 7 ms 4308 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3004 KB Output is correct
20 Correct 2 ms 2996 KB Output is correct
21 Runtime error 1 ms 468 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -