답안 #342019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342019 2021-01-01T05:36:18 Z thecodingwizard Boat (APIO16_boat) C++11
0 / 100
736 ms 4408 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010

const int mod = 1e9+7;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int n; cin >> n;
    ii A[n];
    map<int, int> compress;
    set<int> setValues; setValues.insert(0); setValues.insert(1);
    F0R(i, n) {
        cin >> A[i].f >> A[i].s;
        A[i].s++;
        setValues.insert(A[i].f);
        setValues.insert(A[i].s);
    }
    int idx = 0;
    vector<int> values;
    for (auto x : setValues) {
        compress[x] = idx;
        values.pb(x);
        idx++;
    }
    F0R(i, n) {
        A[i].f = compress[A[i].f];
        A[i].s = compress[A[i].s];
    }

    int ct[values.size()][n+1];
    F0R(i, values.size()-1) {
        F0R(j, n+1) {
            if (j == 0) ct[i][j] = 1;
            else {
                int len = values[i+1]-values[i];
                ct[i][j] = (ll)ct[i][j-1]*(len-(j-1))/j%mod;
            }
        }
        FOR(j, 2, n+1) {
            ct[i][j] = (ct[i][j] + ct[i][j-1]) % mod;
        }
        ct[i][0] = 0;
    }

    int dp[n][values.size()];
    F0R(i, n) {
        F0R(j, values.size()-1) {
            if (j == 0) { dp[i][j] = 1; continue; }

            dp[i][j] = (i>0?dp[i-1][j]:0);
            int num = 0;
            for (int k = i-1; k >= -1; k--) {
                if (A[k+1].f <= j && A[k+1].s > j) num++;
                //cout << j << " " << num << endl;
                dp[i][j] = (dp[i][j] + (ll)(k>=0?dp[k][j-1]:1)*ct[j][num])%mod;
            }

            //cout << "dp[" << i << "][" << j << "]: " << dp[i][j] << endl;
        }
    }

    ll ans = 0;
    FOR(j, 1, values.size()-1) {
        ans = (ans + dp[n-1][j]) % mod;
    }
    cout << ans << endl;

    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:13:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define F0R(i, n) for (int i = 0; i < n; i++)
......
   45 |     F0R(i, values.size()-1) {
      |         ~~~~~~~~~~~~~~~~~~           
boat.cpp:45:5: note: in expansion of macro 'F0R'
   45 |     F0R(i, values.size()-1) {
      |     ^~~
boat.cpp:13:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define F0R(i, n) for (int i = 0; i < n; i++)
......
   61 |         F0R(j, values.size()-1) {
      |             ~~~~~~~~~~~~~~~~~~       
boat.cpp:61:9: note: in expansion of macro 'F0R'
   61 |         F0R(j, values.size()-1) {
      |         ^~~
boat.cpp:14:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | #define FOR(i, a, b) for (int i = a; i < b; i++)
......
   77 |     FOR(j, 1, values.size()-1) {
      |         ~~~~~~~~~~~~~~~~~~~~~           
boat.cpp:77:5: note: in expansion of macro 'FOR'
   77 |     FOR(j, 1, values.size()-1) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 736 ms 4408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 736 ms 4408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 736 ms 4408 KB Output isn't correct
2 Halted 0 ms 0 KB -