답안 #230626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230626 2020-05-10T15:56:29 Z brcode Boat (APIO16_boat) C++14
100 / 100
682 ms 8440 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
const long long MAXN = 501;
long long a[MAXN];
long long b[MAXN];
long long dp[MAXN][2*MAXN];
long long c[2*MAXN][MAXN];
long long fac[2*MAXN];
vector<long long> pts;
long long nxt;
map<long long,long long> m1;
long long power(long long x, long long y, long long p) { 
    long long res = 1;      
  
    x = x % p;  
  
    while (y > 0) 
    { 
        
        if (y & 1) 
            res = (res*x) % p; 
  
        
        y = y>>1;
        x = (x*x) % p; 
    } 
    return res; 
} 
  
long long modInverse(long long n, long long p) { 
    return power(n, p-2, p); 
} 
   

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n;
    cin>>n;
    fac[0] = 1;
    for(long long i=1;i<=1001;i++){
        fac[i] = (1LL*fac[i-1]*i)%MOD; 
        
    }
    
    for(long long i=0;i<n;i++){
        
        cin>>a[i]>>b[i];
        a[i]--;
        pts.push_back(a[i]);
        pts.push_back(b[i]);
    }
    sort(pts.begin(),pts.end());
    pts.resize(unique(pts.begin(),pts.end())-pts.begin());
    for(int i=1;i<pts.size();i++){
        c[i][1] = pts[i]-pts[i-1];
        for(int j=2;j<=n;j++){
            c[i][j] = 1LL*c[i][j-1]*(pts[i]-pts[i-1] +j-1)%MOD*modInverse(j,MOD)%MOD;
        }
    }
    //cout<<c[3][2]<<endl;
    for(long long i=0;i<pts.size();i++){
       
        dp[0][i] = 1;
    }
    for(long long i=1;i<=n;i++){
        dp[i][0] = 1;
        for(long long j=1;j<pts.size();j++){
            dp[i][j] = dp[i][j-1];
            
            long long cnt = 0;
            for(long long k=i;k>=1;k--){
                if(a[k-1]<pts[j] && b[k-1]>=pts[j]){
                    cnt++;
                    dp[i][j]+=(1LL*dp[k-1][j-1]*c[j][cnt]);
                    dp[i][j]%=MOD;
                   
                  // cout<<pts[j]-pts[j-1]<<" "<<cnt<<" "<<nCrModPFermat(pts[j]-pts[j-1],cnt)<<endl;
                }
            }
           // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    cout<<dp[n][pts.size()-1]-1<<'\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<pts.size();i++){
                 ~^~~~~~~~~~~
boat.cpp:64:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<pts.size();i++){
                       ~^~~~~~~~~~~
boat.cpp:70:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(long long j=1;j<pts.size();j++){
                           ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 8184 KB Output is correct
2 Correct 380 ms 8312 KB Output is correct
3 Correct 376 ms 8312 KB Output is correct
4 Correct 378 ms 8184 KB Output is correct
5 Correct 382 ms 8312 KB Output is correct
6 Correct 290 ms 8184 KB Output is correct
7 Correct 281 ms 8312 KB Output is correct
8 Correct 280 ms 8184 KB Output is correct
9 Correct 286 ms 8232 KB Output is correct
10 Correct 276 ms 8376 KB Output is correct
11 Correct 287 ms 8184 KB Output is correct
12 Correct 284 ms 8440 KB Output is correct
13 Correct 284 ms 8264 KB Output is correct
14 Correct 273 ms 8284 KB Output is correct
15 Correct 288 ms 8184 KB Output is correct
16 Correct 78 ms 3704 KB Output is correct
17 Correct 83 ms 3960 KB Output is correct
18 Correct 80 ms 3832 KB Output is correct
19 Correct 84 ms 3832 KB Output is correct
20 Correct 83 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 8184 KB Output is correct
2 Correct 380 ms 8312 KB Output is correct
3 Correct 376 ms 8312 KB Output is correct
4 Correct 378 ms 8184 KB Output is correct
5 Correct 382 ms 8312 KB Output is correct
6 Correct 290 ms 8184 KB Output is correct
7 Correct 281 ms 8312 KB Output is correct
8 Correct 280 ms 8184 KB Output is correct
9 Correct 286 ms 8232 KB Output is correct
10 Correct 276 ms 8376 KB Output is correct
11 Correct 287 ms 8184 KB Output is correct
12 Correct 284 ms 8440 KB Output is correct
13 Correct 284 ms 8264 KB Output is correct
14 Correct 273 ms 8284 KB Output is correct
15 Correct 288 ms 8184 KB Output is correct
16 Correct 78 ms 3704 KB Output is correct
17 Correct 83 ms 3960 KB Output is correct
18 Correct 80 ms 3832 KB Output is correct
19 Correct 84 ms 3832 KB Output is correct
20 Correct 83 ms 3832 KB Output is correct
21 Correct 456 ms 7928 KB Output is correct
22 Correct 461 ms 8056 KB Output is correct
23 Correct 441 ms 7928 KB Output is correct
24 Correct 432 ms 7800 KB Output is correct
25 Correct 461 ms 7800 KB Output is correct
26 Correct 556 ms 7804 KB Output is correct
27 Correct 583 ms 7800 KB Output is correct
28 Correct 557 ms 7976 KB Output is correct
29 Correct 555 ms 7672 KB Output is correct
30 Correct 292 ms 8184 KB Output is correct
31 Correct 286 ms 8184 KB Output is correct
32 Correct 277 ms 8184 KB Output is correct
33 Correct 288 ms 8184 KB Output is correct
34 Correct 294 ms 8220 KB Output is correct
35 Correct 390 ms 8184 KB Output is correct
36 Correct 389 ms 8184 KB Output is correct
37 Correct 399 ms 8180 KB Output is correct
38 Correct 384 ms 8316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1664 KB Output is correct
2 Correct 11 ms 1664 KB Output is correct
3 Correct 12 ms 1664 KB Output is correct
4 Correct 11 ms 1792 KB Output is correct
5 Correct 12 ms 1664 KB Output is correct
6 Correct 13 ms 1792 KB Output is correct
7 Correct 12 ms 1664 KB Output is correct
8 Correct 12 ms 1664 KB Output is correct
9 Correct 12 ms 1792 KB Output is correct
10 Correct 12 ms 1664 KB Output is correct
11 Correct 12 ms 1792 KB Output is correct
12 Correct 12 ms 1792 KB Output is correct
13 Correct 12 ms 1664 KB Output is correct
14 Correct 12 ms 1792 KB Output is correct
15 Correct 12 ms 1792 KB Output is correct
16 Correct 9 ms 1408 KB Output is correct
17 Correct 9 ms 1280 KB Output is correct
18 Correct 9 ms 1408 KB Output is correct
19 Correct 9 ms 1280 KB Output is correct
20 Correct 8 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 8184 KB Output is correct
2 Correct 380 ms 8312 KB Output is correct
3 Correct 376 ms 8312 KB Output is correct
4 Correct 378 ms 8184 KB Output is correct
5 Correct 382 ms 8312 KB Output is correct
6 Correct 290 ms 8184 KB Output is correct
7 Correct 281 ms 8312 KB Output is correct
8 Correct 280 ms 8184 KB Output is correct
9 Correct 286 ms 8232 KB Output is correct
10 Correct 276 ms 8376 KB Output is correct
11 Correct 287 ms 8184 KB Output is correct
12 Correct 284 ms 8440 KB Output is correct
13 Correct 284 ms 8264 KB Output is correct
14 Correct 273 ms 8284 KB Output is correct
15 Correct 288 ms 8184 KB Output is correct
16 Correct 78 ms 3704 KB Output is correct
17 Correct 83 ms 3960 KB Output is correct
18 Correct 80 ms 3832 KB Output is correct
19 Correct 84 ms 3832 KB Output is correct
20 Correct 83 ms 3832 KB Output is correct
21 Correct 456 ms 7928 KB Output is correct
22 Correct 461 ms 8056 KB Output is correct
23 Correct 441 ms 7928 KB Output is correct
24 Correct 432 ms 7800 KB Output is correct
25 Correct 461 ms 7800 KB Output is correct
26 Correct 556 ms 7804 KB Output is correct
27 Correct 583 ms 7800 KB Output is correct
28 Correct 557 ms 7976 KB Output is correct
29 Correct 555 ms 7672 KB Output is correct
30 Correct 292 ms 8184 KB Output is correct
31 Correct 286 ms 8184 KB Output is correct
32 Correct 277 ms 8184 KB Output is correct
33 Correct 288 ms 8184 KB Output is correct
34 Correct 294 ms 8220 KB Output is correct
35 Correct 390 ms 8184 KB Output is correct
36 Correct 389 ms 8184 KB Output is correct
37 Correct 399 ms 8180 KB Output is correct
38 Correct 384 ms 8316 KB Output is correct
39 Correct 12 ms 1664 KB Output is correct
40 Correct 11 ms 1664 KB Output is correct
41 Correct 12 ms 1664 KB Output is correct
42 Correct 11 ms 1792 KB Output is correct
43 Correct 12 ms 1664 KB Output is correct
44 Correct 13 ms 1792 KB Output is correct
45 Correct 12 ms 1664 KB Output is correct
46 Correct 12 ms 1664 KB Output is correct
47 Correct 12 ms 1792 KB Output is correct
48 Correct 12 ms 1664 KB Output is correct
49 Correct 12 ms 1792 KB Output is correct
50 Correct 12 ms 1792 KB Output is correct
51 Correct 12 ms 1664 KB Output is correct
52 Correct 12 ms 1792 KB Output is correct
53 Correct 12 ms 1792 KB Output is correct
54 Correct 9 ms 1408 KB Output is correct
55 Correct 9 ms 1280 KB Output is correct
56 Correct 9 ms 1408 KB Output is correct
57 Correct 9 ms 1280 KB Output is correct
58 Correct 8 ms 1280 KB Output is correct
59 Correct 496 ms 8312 KB Output is correct
60 Correct 487 ms 8288 KB Output is correct
61 Correct 481 ms 8312 KB Output is correct
62 Correct 503 ms 8312 KB Output is correct
63 Correct 491 ms 8312 KB Output is correct
64 Correct 635 ms 8440 KB Output is correct
65 Correct 682 ms 8184 KB Output is correct
66 Correct 637 ms 8324 KB Output is correct
67 Correct 640 ms 8408 KB Output is correct
68 Correct 636 ms 8312 KB Output is correct
69 Correct 516 ms 8212 KB Output is correct
70 Correct 542 ms 8416 KB Output is correct
71 Correct 527 ms 8312 KB Output is correct
72 Correct 536 ms 8184 KB Output is correct
73 Correct 537 ms 8280 KB Output is correct
74 Correct 103 ms 3832 KB Output is correct
75 Correct 107 ms 3832 KB Output is correct
76 Correct 118 ms 3960 KB Output is correct
77 Correct 111 ms 3960 KB Output is correct
78 Correct 103 ms 3804 KB Output is correct