Submission #532158

# Submission time Handle Problem Language Result Execution time Memory
532158 2022-03-02T07:55:02 Z 79brue Boat (APIO16_boat) C++14
9 / 100
11 ms 564 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll mpow(ll x, ll y){
    if(!y) return 1;
    if(y&1) return (mpow(x, y-1)*x)%MOD;
    ll tmp = mpow(x, y/2);
    return (tmp*tmp)%MOD;
}

int n;
int a[502], b[502];
map<int, int> idx;
vector<int> renumber;

ll DP[1002], DPsum[1002];
ll DP2[1002][1002];
ll modInv[1002];
ll ans;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d %d", &a[i], &b[i]);
        b[i]++;
        renumber.push_back(a[i]);
        renumber.push_back(b[i]);
    }
    sort(renumber.begin(), renumber.end());
    renumber.erase(unique(renumber.begin(), renumber.end()), renumber.end());
    for(int i=0; i<(int)renumber.size(); i++){
        idx[renumber[i]] = i;
    }

    for(int i=1; i<=1000; i++){
        modInv[i] = mpow(i, MOD-2);
    }

    DP[0] = 1;
    for(int i=1; i<(int)renumber.size(); i++){
        int s = renumber[i-1], e = renumber[i];
        DPsum[0] = 1;
        vector<int> tv;

        for(int j=1; j<=n; j++){
            DPsum[j] = (DPsum[j-1] + DP[j]) % MOD;
            if(a[j] <= s && e <= b[j]) tv.push_back(j);
        }

        for(int j=1; j<=(int)tv.size() && j<=e-s; j++){
            for(int k=j-1; k<(int)tv.size(); k++){
                if(j==1){
                    DP2[j][k] = DPsum[tv[k]-1]*(e-s);
                    if(k!=0) DP2[j][k] += DP2[j][k-1];
                    DP2[j][k]%=MOD;
                }
                else{
                    DP2[j][j] = ((DP2[j-1][k-1] * modInv[j]) % MOD) * ((e-s+1) - i) + DP2[j][k-1];
                    DP2[j][k]%=MOD;
                }
            }
        }

        for(int j=1; j<=(int)tv.size() && j<=e-s; j++){
            for(int k=j-1; k<(int)tv.size(); k++){
                int tmp = (DP2[j][k] - (k?DP2[j][k-1]:0) + MOD) % MOD;
                DP[tv[k]] += tmp;
                DP[tv[k]] %= MOD;
            }
        }
    }

    for(int i=1; i<=n; i++) ans = (ans + DP[i]) % MOD;
    printf("%lld", ans);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d", &a[i], &b[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 4 ms 324 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 5 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 4 ms 332 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 5 ms 396 KB Output is correct
12 Correct 4 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 4 ms 320 KB Output is correct
15 Correct 4 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 4 ms 324 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 5 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 4 ms 332 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 5 ms 396 KB Output is correct
12 Correct 4 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 4 ms 320 KB Output is correct
15 Correct 4 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Incorrect 11 ms 564 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 4 ms 324 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 5 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 4 ms 332 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 5 ms 396 KB Output is correct
12 Correct 4 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 4 ms 320 KB Output is correct
15 Correct 4 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Incorrect 11 ms 564 KB Output isn't correct
22 Halted 0 ms 0 KB -