답안 #490326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490326 2021-11-27T06:28:26 Z JerryLiu06 Boat (APIO16_boat) C++17
0 / 100
3 ms 2380 KB
// https://oj.uz/problem/view/APIO16_boat

#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using db = double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0);
#define FASTIOF ios_base::sync_with_stdio(false); fin.tie(0);

#define mp make_pair
#define f first
#define s second
 
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert 
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
 
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }

const int MOD = 1e9 + 7;
const int MX = 510;
const ll INF = 1e18;

struct mint {
	int v; explicit operator int() const { return v; }

	mint() { v = 0; } mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD); if (v < 0) v += MOD; }

	friend bool operator==(const mint& a, const mint& b) { return a.v == b.v; }
	friend bool operator!=(const mint& a, const mint& b) { return !(a == b); }
	friend bool operator<(const mint& a, const mint& b) { return a.v < b.v; }

	mint& operator+=(const mint& m) { if ((v += m.v) >= MOD) v -= MOD; return *this; }
	mint& operator-=(const mint& m) { if ((v -= m.v) < 0) v += MOD; return *this; }
	mint& operator*=(const mint& m) { v = int((ll) v * m.v % MOD); return *this; }
	mint& operator/=(const mint& m) { return (*this) *= inv(m); }

    friend mint pow(mint a, long long p) {
		mint ans = 1; for ( ; p; p /= 2, a *= a) if (p & 1) ans *= a; return ans; 
    }
	friend mint inv(const mint& a) { return pow(a, MOD - 2); }

	mint operator-() const { return mint(-v); }
	mint& operator++() { return *this += 1; }
	mint& operator--() { return *this -= 1; }

	friend mint operator+(mint a, const mint& b) { return a += b; }
	friend mint operator-(mint a, const mint& b) { return a -= b; }
	friend mint operator*(mint a, const mint& b) { return a *= b; }
	friend mint operator/(mint a, const mint& b) { return a /= b; }
};

int N, M = 0, A[MX], B[MX]; vi al; mint DP[MX][2 * MX], in[MX];

int main() {
    FASTIO;
    
    cin >> N;

    FOR(i, 1, N + 1) {
        cin >> A[i] >> B[i]; 

        B[i]++;

        al.pb(A[i]);
        al.pb(B[i]);

        in[i] = inv((mint) i);
    }
    remDup(al);

    FOR(i, 1, N + 1) {
        A[i] = ub(all(al), A[i]) - al.bg();
        B[i] = ub(all(al), B[i]) - al.bg();

        ckmax(M, A[i]);
        ckmax(M, B[i]);
    }
    
    DP[0][1] = 1;

    FOR(i, 1, N + 1) {
        FOR(j, 1, 2 * MX) {
            DP[i][j] = DP[i - 1][j];
            
            DP[i - 1][j] += DP[i - 1][j - 1];
        }
        FOR(j, A[i] + 1, B[i] + 1) {
            int curL = al[j - 2];
            int curR = al[j - 1] - 1;

            int cntContained = 0;

            mint curChoose = 1;
            mint val = curR - curL + 1;

            R0F(k, i) {
                if (!(A[k + 1] <= curL && curR <= B[k + 1] - 1)) {
                    continue;
                }
                cntContained++;

                curChoose *= (val - cntContained + 1);
                curChoose *= in[cntContained];

                DP[i][j] += DP[k][j - 1] * curChoose;
            }
        }
    }
    mint ans = 0;

    FOR(i, 2, M + 1) {
        ans += DP[N][i];
    }
    cout << int(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -