답안 #469995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469995 2021-09-02T13:52:51 Z ymm Boat (APIO16_boat) C++17
9 / 100
569 ms 4432 KB
///
///   ♪ Pizza mozzarella rella rella rella... ♪
///

#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = (l); x < (r); ++x)
#define LoopR(x, l, r) for(int x = (r)-1; x >= (l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef          long long   ll;
typedef unsigned long long  ull;
typedef std::pair<int,int>  pii;
typedef std::pair<ll ,ll >  pll;
using namespace std;

const int mod = 1e9 + 7;
const int N = 512;
vector<int> cmp;
int l[N], r[N];
int n;

ll dp[N][2*N];
ll fct[2*N], fci[2*N];
ll inv[2*N];
ll Inv(ll x){
    ll ans = 1;
    for(ll y = mod-2; y; y >>= 1){
        if(y&1) ans = ans*x % mod;
        x = x*x % mod;
    }
    return ans;
}

int main()
{
    FAST;
    cin >> n;
    inv[0] = fci[0] = fct[0] = 1;
    Loop(i,1,2*N) fct[i] = fct[i-1]*i % mod, fci[i] = Inv(fct[i]), inv[i] = Inv(i);
    Loop(i,0,n)
    {
        cin >> l[i] >> r[i];
        ++r[i];
        cmp.push_back(l[i]);
        cmp.push_back(r[i]);
    }
    sort(all(cmp)); cmp.resize(unique(all(cmp))-cmp.begin());
    Loop(i,0,2*N) dp[0][i] = 1;

    Loop(i,0,n)
    {
        Loop(j,0,cmp.size()-1)
        {
            ll m = cmp[j+1] - cmp[j];
            ll X = 1;
            int k = 0;
            LoopR(p,0,i+1)
            {
                if(r[p] <= cmp[j] || cmp[j+1] <= l[p]) continue;
                X = X*(m+k) % mod;
                X = X*inv[k+1] % mod;
                ++k;
                dp[i+1][j] = (dp[i+1][j] + X*dp[p][j]) % mod;
            }
        }

        ll sum = 1;
        Loop(j,0,cmp.size())
            sum += dp[i+1][j],
            dp[i+1][j] = sum - dp[i+1][j];
    }

    //Loop(i,0,n+1) {Loop(j,0,cmp.size()) cout << dp[i][j] << ' '; cout << '\n';}
    cout << (dp[n][cmp.size()-1]+mod-1)%mod << '\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:8:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define Loop(x, l, r) for(int x = (l); x < (r); ++x)
      |                                          ^
boat.cpp:57:9: note: in expansion of macro 'Loop'
   57 |         Loop(j,0,cmp.size()-1)
      |         ^~~~
boat.cpp:8:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define Loop(x, l, r) for(int x = (l); x < (r); ++x)
      |                                          ^
boat.cpp:73:9: note: in expansion of macro 'Loop'
   73 |         Loop(j,0,cmp.size())
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 4380 KB Output is correct
2 Correct 262 ms 4244 KB Output is correct
3 Correct 261 ms 4292 KB Output is correct
4 Correct 252 ms 4336 KB Output is correct
5 Correct 252 ms 4428 KB Output is correct
6 Correct 158 ms 4316 KB Output is correct
7 Correct 156 ms 4264 KB Output is correct
8 Correct 164 ms 4292 KB Output is correct
9 Correct 162 ms 4312 KB Output is correct
10 Correct 157 ms 4292 KB Output is correct
11 Correct 158 ms 4288 KB Output is correct
12 Correct 167 ms 4292 KB Output is correct
13 Correct 159 ms 4304 KB Output is correct
14 Correct 149 ms 4292 KB Output is correct
15 Correct 160 ms 4432 KB Output is correct
16 Correct 54 ms 2244 KB Output is correct
17 Correct 56 ms 2244 KB Output is correct
18 Correct 55 ms 2296 KB Output is correct
19 Correct 58 ms 2332 KB Output is correct
20 Correct 56 ms 2308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 4380 KB Output is correct
2 Correct 262 ms 4244 KB Output is correct
3 Correct 261 ms 4292 KB Output is correct
4 Correct 252 ms 4336 KB Output is correct
5 Correct 252 ms 4428 KB Output is correct
6 Correct 158 ms 4316 KB Output is correct
7 Correct 156 ms 4264 KB Output is correct
8 Correct 164 ms 4292 KB Output is correct
9 Correct 162 ms 4312 KB Output is correct
10 Correct 157 ms 4292 KB Output is correct
11 Correct 158 ms 4288 KB Output is correct
12 Correct 167 ms 4292 KB Output is correct
13 Correct 159 ms 4304 KB Output is correct
14 Correct 149 ms 4292 KB Output is correct
15 Correct 160 ms 4432 KB Output is correct
16 Correct 54 ms 2244 KB Output is correct
17 Correct 56 ms 2244 KB Output is correct
18 Correct 55 ms 2296 KB Output is correct
19 Correct 58 ms 2332 KB Output is correct
20 Correct 56 ms 2308 KB Output is correct
21 Incorrect 569 ms 4344 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 4380 KB Output is correct
2 Correct 262 ms 4244 KB Output is correct
3 Correct 261 ms 4292 KB Output is correct
4 Correct 252 ms 4336 KB Output is correct
5 Correct 252 ms 4428 KB Output is correct
6 Correct 158 ms 4316 KB Output is correct
7 Correct 156 ms 4264 KB Output is correct
8 Correct 164 ms 4292 KB Output is correct
9 Correct 162 ms 4312 KB Output is correct
10 Correct 157 ms 4292 KB Output is correct
11 Correct 158 ms 4288 KB Output is correct
12 Correct 167 ms 4292 KB Output is correct
13 Correct 159 ms 4304 KB Output is correct
14 Correct 149 ms 4292 KB Output is correct
15 Correct 160 ms 4432 KB Output is correct
16 Correct 54 ms 2244 KB Output is correct
17 Correct 56 ms 2244 KB Output is correct
18 Correct 55 ms 2296 KB Output is correct
19 Correct 58 ms 2332 KB Output is correct
20 Correct 56 ms 2308 KB Output is correct
21 Incorrect 569 ms 4344 KB Output isn't correct
22 Halted 0 ms 0 KB -