답안 #342007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342007 2021-01-01T02:20:39 Z thecodingwizard Boat (APIO16_boat) C++11
9 / 100
9 ms 4332 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 dp[n][values.size()];
    int dpSum[n][values.size()];
    F0R(i, n) {
        F0R(j, values.size()-1) {
            if (i == 0 && j == 0) { dp[i][j] = 1; continue; }
            if (A[i].f <= j && A[i].s > j) {
                // range is within [a...b]
                ll numValues = values[j+1]-values[j];
                dp[i][j] = ((ll)(i==0?0:dp[i-1][j]) + (ll)(i>0&&j>0?dpSum[i-1][j-1]:1)*numValues) % mod;
            } else {
                // range is outside of [a...b]
                dp[i][j] = i==0?0:dp[i-1][j];
            }
            if (j == 0) assert(dp[i][j] == 1);
        }
        F0R(j, values.size()-1) {
            dpSum[i][j] = ((ll)(j>0?dpSum[i][j-1]:0)+dp[i][j])%mod;
        }
    }
    cout << dpSum[n-1][values.size()-2]-1 << 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++)
......
   47 |         F0R(j, values.size()-1) {
      |             ~~~~~~~~~~~~~~~~~~       
boat.cpp:47:9: note: in expansion of macro 'F0R'
   47 |         F0R(j, 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++)
......
   59 |         F0R(j, values.size()-1) {
      |             ~~~~~~~~~~~~~~~~~~       
boat.cpp:59:9: note: in expansion of macro 'F0R'
   59 |         F0R(j, values.size()-1) {
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4332 KB Output is correct
2 Correct 8 ms 4332 KB Output is correct
3 Correct 8 ms 4332 KB Output is correct
4 Correct 8 ms 4332 KB Output is correct
5 Correct 8 ms 4332 KB Output is correct
6 Correct 7 ms 4332 KB Output is correct
7 Correct 7 ms 4332 KB Output is correct
8 Correct 7 ms 4332 KB Output is correct
9 Correct 7 ms 4332 KB Output is correct
10 Correct 8 ms 4332 KB Output is correct
11 Correct 7 ms 4332 KB Output is correct
12 Correct 8 ms 4332 KB Output is correct
13 Correct 8 ms 4332 KB Output is correct
14 Correct 8 ms 4332 KB Output is correct
15 Correct 9 ms 4332 KB Output is correct
16 Correct 2 ms 1004 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 2 ms 1132 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4332 KB Output is correct
2 Correct 8 ms 4332 KB Output is correct
3 Correct 8 ms 4332 KB Output is correct
4 Correct 8 ms 4332 KB Output is correct
5 Correct 8 ms 4332 KB Output is correct
6 Correct 7 ms 4332 KB Output is correct
7 Correct 7 ms 4332 KB Output is correct
8 Correct 7 ms 4332 KB Output is correct
9 Correct 7 ms 4332 KB Output is correct
10 Correct 8 ms 4332 KB Output is correct
11 Correct 7 ms 4332 KB Output is correct
12 Correct 8 ms 4332 KB Output is correct
13 Correct 8 ms 4332 KB Output is correct
14 Correct 8 ms 4332 KB Output is correct
15 Correct 9 ms 4332 KB Output is correct
16 Correct 2 ms 1004 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 2 ms 1132 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1132 KB Output is correct
21 Incorrect 7 ms 3948 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4332 KB Output is correct
2 Correct 8 ms 4332 KB Output is correct
3 Correct 8 ms 4332 KB Output is correct
4 Correct 8 ms 4332 KB Output is correct
5 Correct 8 ms 4332 KB Output is correct
6 Correct 7 ms 4332 KB Output is correct
7 Correct 7 ms 4332 KB Output is correct
8 Correct 7 ms 4332 KB Output is correct
9 Correct 7 ms 4332 KB Output is correct
10 Correct 8 ms 4332 KB Output is correct
11 Correct 7 ms 4332 KB Output is correct
12 Correct 8 ms 4332 KB Output is correct
13 Correct 8 ms 4332 KB Output is correct
14 Correct 8 ms 4332 KB Output is correct
15 Correct 9 ms 4332 KB Output is correct
16 Correct 2 ms 1004 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 2 ms 1132 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1132 KB Output is correct
21 Incorrect 7 ms 3948 KB Output isn't correct
22 Halted 0 ms 0 KB -