답안 #165381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165381 2019-11-26T17:07:39 Z combi1k1 Boat (APIO16_boat) C++14
0 / 100
8 ms 2424 KB
#include<bits/stdc++.h>

using namespace std;

const int   N   = 505;
const int   mod = 1e9 + 7;

void add(int &a,int b)  {
    a += b;
    if (a >= mod)
        a -= mod;
}
void sub(int &a,int b)  {
    a -= b;
    if (a <  0)
        a -= mod;
}
int mul(int a,int b)    {
    return  1ll * a * b % mod;
}

int inv[N];

int a[N], b[N];
int f[N][1010];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    inv[1] = 1;

    for(int i = 2 ; i < N ; ++i)
        inv[i] = mul(inv[mod % i],mod - mod / i);

    int n;  cin >> n;

    vector<int> comp;

    for(int i = 1 ; i <= n ; ++i)   {
        cin >> a[i];    comp.push_back(a[i] - 1);
        cin >> b[i];    comp.push_back(b[i]);
    }
    sort(comp.begin(),comp.end());
    comp.erase(unique(comp.begin(),comp.end()),comp.end());

    for(int i = 1 ; i <= n ; ++i)   {
        a[i] = lower_bound(comp.begin(),comp.end(),a[i]) - comp.begin();
        b[i] = lower_bound(comp.begin(),comp.end(),b[i]) - comp.begin();
    }
    for(int i = 0 ; i < comp.size() ; ++i)
        f[0][i] = 1;
    for(int i = 1 ; i <= n ; ++i)   {
        assert(a[i]);
        f[i][0] = 1;
        for(int j = a[i] ; j <= b[i] ; ++j) {
            f[i][j] = mul(f[i - 1][j - 1],comp[j] - comp[j - 1]);

            int cnt = 1;
            int Max = comp[j] - comp[j - 1] - 1;
            int way = Max;

            for(int k = i - 1 ; k ; --k)    if (a[k] <= j && j <= b[k]) {
                way = mul(way,Max++);
                way = mul(way,inv[++cnt]);

                add(f[i][j],mul(f[k - 1][j - 1],way));
            }
        }
        for(int j = 1 ; j < comp.size() ; ++j)
            //cout << f[i][j] << " ",
            add(f[i][j],f[i - 1][j]),
            add(f[i][j],f[i][j - 1]),
            sub(f[i][j],f[i - 1][j - 1]);
        //cout << "\n";
    }

    int ans = f[n][comp.size() - 1];
    sub(ans,1);

    cout << ans << endl;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < comp.size() ; ++i)
                     ~~^~~~~~~~~~~~~
boat.cpp:70:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1 ; j < comp.size() ; ++j)
                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -