Submission #760538

# Submission time Handle Problem Language Result Execution time Memory
760538 2023-06-17T18:22:54 Z Username4132 Boat (APIO16_boat) C++14
36 / 100
2000 ms 2772 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)
#define PB push_back

const int MAXN=510, MOD=1000000007;
int n, le[MAXN], ri[MAXN], arr[2*MAXN][MAXN];
bool adj[2*MAXN][MAXN];
vector<int> pt;

ll ex(ll b, int e){
    ll ret=1;
    while(e>0){
        if(e&1) ret=(ret*b)%MOD;
        b = (b*b)%MOD;
        e>>=1;
    }
    return ret;
}

int main(){
    scanf("%d", &n);
    forn(i, n) scanf("%d %d", le+i, ri+i), pt.PB(le[i]), pt.PB(ri[i]+1);
    sort(pt.begin(), pt.end());
    pt.erase(unique(pt.begin(), pt.end()), pt.end());
    forn(i, n){
        auto itr = lower_bound(pt.begin(),  pt.end(), le[i]);
        for(; itr!=pt.end() && (*itr)<=ri[i]; ++itr) adj[itr-pt.begin()][i]=true;
    }
    forn(i, pt.size()-1){
        forn(j, n){
            arr[i+1][j]=(arr[i][j]-(j==0? 0 : arr[i][j-1]) + MOD)%MOD;
            if(adj[i][j]){
                int cnt=0, m=pt[i+1]-pt[i];
                ll comb=m;
                dforn(k, j){
                    int dif = (arr[i][k] - (k==0? 0 : arr[i][k-1]) + MOD)%MOD;
                    arr[i+1][j]=(arr[i+1][j] + comb*dif)%MOD;
                    if(adj[i][k]){
                        ++cnt;
                        comb=(((comb*(m+cnt))%MOD)*ex(cnt+1, MOD-2))%MOD;
                    }
                }
                arr[i+1][j]=(arr[i+1][j]+comb)%MOD;
            }
        }
        forn(j, n-1) arr[i+1][j+1]=(arr[i+1][j+1]+arr[i+1][j])%MOD;
    }
    printf("%d\n", arr[pt.size()-1][n-1]);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:27:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     forn(i, n) scanf("%d %d", le+i, ri+i), pt.PB(le[i]), pt.PB(ri[i]+1);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2772 KB Output is correct
2 Correct 5 ms 2752 KB Output is correct
3 Correct 5 ms 2772 KB Output is correct
4 Correct 5 ms 2700 KB Output is correct
5 Correct 5 ms 2772 KB Output is correct
6 Correct 4 ms 2748 KB Output is correct
7 Correct 5 ms 2772 KB Output is correct
8 Correct 4 ms 2752 KB Output is correct
9 Correct 5 ms 2752 KB Output is correct
10 Correct 5 ms 2772 KB Output is correct
11 Correct 5 ms 2772 KB Output is correct
12 Correct 5 ms 2772 KB Output is correct
13 Correct 4 ms 2772 KB Output is correct
14 Correct 5 ms 2756 KB Output is correct
15 Correct 5 ms 2772 KB Output is correct
16 Correct 2 ms 700 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2772 KB Output is correct
2 Correct 5 ms 2752 KB Output is correct
3 Correct 5 ms 2772 KB Output is correct
4 Correct 5 ms 2700 KB Output is correct
5 Correct 5 ms 2772 KB Output is correct
6 Correct 4 ms 2748 KB Output is correct
7 Correct 5 ms 2772 KB Output is correct
8 Correct 4 ms 2752 KB Output is correct
9 Correct 5 ms 2752 KB Output is correct
10 Correct 5 ms 2772 KB Output is correct
11 Correct 5 ms 2772 KB Output is correct
12 Correct 5 ms 2772 KB Output is correct
13 Correct 4 ms 2772 KB Output is correct
14 Correct 5 ms 2756 KB Output is correct
15 Correct 5 ms 2772 KB Output is correct
16 Correct 2 ms 700 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Execution timed out 2019 ms 2604 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 700 KB Output is correct
2 Correct 12 ms 740 KB Output is correct
3 Correct 16 ms 724 KB Output is correct
4 Correct 17 ms 816 KB Output is correct
5 Correct 19 ms 816 KB Output is correct
6 Correct 38 ms 732 KB Output is correct
7 Correct 39 ms 716 KB Output is correct
8 Correct 39 ms 748 KB Output is correct
9 Correct 38 ms 744 KB Output is correct
10 Correct 38 ms 764 KB Output is correct
11 Correct 19 ms 724 KB Output is correct
12 Correct 12 ms 724 KB Output is correct
13 Correct 16 ms 784 KB Output is correct
14 Correct 16 ms 724 KB Output is correct
15 Correct 18 ms 816 KB Output is correct
16 Correct 13 ms 596 KB Output is correct
17 Correct 9 ms 596 KB Output is correct
18 Correct 11 ms 636 KB Output is correct
19 Correct 9 ms 596 KB Output is correct
20 Correct 12 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2772 KB Output is correct
2 Correct 5 ms 2752 KB Output is correct
3 Correct 5 ms 2772 KB Output is correct
4 Correct 5 ms 2700 KB Output is correct
5 Correct 5 ms 2772 KB Output is correct
6 Correct 4 ms 2748 KB Output is correct
7 Correct 5 ms 2772 KB Output is correct
8 Correct 4 ms 2752 KB Output is correct
9 Correct 5 ms 2752 KB Output is correct
10 Correct 5 ms 2772 KB Output is correct
11 Correct 5 ms 2772 KB Output is correct
12 Correct 5 ms 2772 KB Output is correct
13 Correct 4 ms 2772 KB Output is correct
14 Correct 5 ms 2756 KB Output is correct
15 Correct 5 ms 2772 KB Output is correct
16 Correct 2 ms 700 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Execution timed out 2019 ms 2604 KB Time limit exceeded
22 Halted 0 ms 0 KB -