답안 #163326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163326 2019-11-12T16:22:35 Z Akashi Boat (APIO16_boat) C++14
0 / 100
17 ms 9336 KB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

struct interv{
    int x, y;
    bool operator < (const interv &aux)const{
        if(y != aux.y) return y < aux.y;
        return x < aux.x;
    }
};
interv a[501];

int n, sz;
int dif[2001];
int inv_mod[2001];
int d[501][2001];
int C[2001][2001];
vector <int> v;

int lgput(int x, int p){
    int aux = x, ans = 1;
    for(int i = 1; i <= p ; i = i << 1){
        if(i & p) ans = (1LL * ans * aux) % MOD;
        aux = (1LL * aux * aux) % MOD;
    }
    return ans;
}

void calc_comb(int lin, int n, int k){
    int prod = 1;
    C[lin][0] = 1;
    for(int i = 1; i <= k ; ++i){
        prod = (1LL * prod * (n - i + 1)) % MOD;
        prod = (1LL * prod * inv_mod[i]) % MOD;
        C[lin][i] = prod;
    }
}

void prec(){
    for(int i = 1; i <= n ; ++i)
        inv_mod[i] = lgput(i, MOD - 2);

    for(int k = 2; k <= sz ; ++k)
        calc_comb(k, dif[k], min(n, dif[k]));
}

int main()
{
//    freopen("1.in", "r", stdin);

    scanf("%d", &n);
    for(int i = 1; i <= n ; ++i){
        scanf("%d%d", &a[i].x, &a[i].y);
        v.push_back(a[i].x);
        v.push_back(a[i].x - 1);
        v.push_back(a[i].y);
        v.push_back(a[i].y - 1);
    }

    sort(a + 1, a + n + 1);

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    sz = v.size();
    for(int i = 2; i <= sz ; ++i) dif[i] = v[i - 1] - v[i - 2];

    for(int i = 1; i <= n ; ++i){
        a[i].x = lower_bound(v.begin(), v.end(), a[i].x) - v.begin() + 1;
        a[i].y = lower_bound(v.begin(), v.end(), a[i].y) - v.begin() + 1;
    }

    prec();
  
    for(int j = 0; j <= sz ; ++j) d[0][j] = 1;
    for(int j = a[1].x; j <= a[1].y ; ++j) d[1][j] = dif[j];

    d[1][0] += 1;
    for(int j = 1; j <= sz ; ++j){
        d[1][j] += d[1][j - 1];
        if(d[1][j] >= MOD) d[1][j] -= MOD;
    }

    for(int i = 2; i <= n ; ++i){
        for(int j = a[i].x; j <= a[i].y ; ++j){
            for(int k = 1; k <= i ; ++k){
                if(a[k].y < j || dif[j] < i - k + 1) continue ;

                d[i][j] = d[i][j] + (1LL * d[k - 1][j - 1] * C[j][i - k + 1]) % MOD;
                if(d[i][j] >= MOD) d[i][j] -= MOD;
            }
        }

        for(int j = 1; j <= sz ; ++j){
            d[i][j] += d[i][j - 1];
            if(d[i][j] >= MOD) d[i][j] -= MOD;
        }

        for(int j = 0; j <= sz ; ++j){
            d[i][j] += d[i - 1][j];
            if(d[i][j] >= MOD) d[i][j] -= MOD;
        }
    }

    --d[n][sz];
    if(d[n][sz] < 0) d[n][sz] += MOD;
    printf("%d", d[n][sz]);

    return 0;
}


















Compilation message

boat.cpp: In function 'int main()':
boat.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i].x, &a[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 9336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 9336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 9336 KB Output isn't correct
2 Halted 0 ms 0 KB -