답안 #547871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547871 2022-04-11T23:50:49 Z Olympia Boat (APIO16_boat) C++17
0 / 100
427 ms 8176 KB
#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string>
#include <queue>
#include <map>

const int MOD = 1e9 + 7;
using namespace std;
int64_t binPow (int64_t x, int64_t y) {
    int64_t ans = 1, res = x;
    while (y) {
        if (y & 1) ans *= res, ans %= MOD;
        res *= res, res %= MOD, y /= 2;
    }
    return ans;
}
int64_t inv (int64_t x) {
    return binPow(x, MOD - 2);
}
vector<pair<int,int>> compress (vector<pair<int,int>> &vec) {
    set<int> s;
    for (auto& p: vec) {
        s.insert(p.first), s.insert(p.second);
    }
    vector<int> v; for (int i: s) v.push_back(i);
    vector<pair<int,int>> grids;
    for (int i = 0; i < v.size(); i++) {
        grids.emplace_back(v[i], v[i]);
        if (i + 1 != v.size() && v[i] + 1 <= v[i + 1] - 1) grids.emplace_back(v[i] + 1, v[i + 1] - 1);
    }
    return grids;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N; cin >> N;
    vector<pair<int,int>> points(N);
    for (int i = 0; i < N; i++) cin >> points[i].first >> points[i].second;
    vector<pair<int,int>> grid = compress(points); 
    int64_t combo[grid.size()][N + 1];
    for (int i = 0; i < grid.size(); i++) {
        combo[i][0] = 1;
        for (int j = 1; j <= N; j++) {
            combo[i][j] = ((combo[i][j - 1] * inv(j)) % MOD * (int64_t)(grid[i].second - grid[i].first - j + 2)) % MOD;
        }
        for (int j = grid[i].second - grid[i].first + 2; j <= N; j++) {
            combo[i][j] = 0;
        }
    }
    int64_t dp[N][grid.size()];
    for (int i = 0; i < grid.size(); i++) {
        dp[0][i] = (grid[i].first >= points[0].first && grid[i].second <= points[0].second) * (points[0].second - points[0].first + 1);
    }
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < grid.size(); j++) {
            dp[i][j] = (j == 0) ? 1 : dp[i][j - 1];
            int pos = 0;
            for (int k = i; k >= 0; k--) {
                pos += (grid[j].first >= points[k].first && grid[j].second <= points[k].second);
                dp[i][j] += ((k == 0 || j == 0) ? 1 : dp[k - 1][j - 1]) * combo[j][pos];
            }
        }
    }
    cout << (dp[N - 1][grid.size() - 1] + MOD - 1) % MOD;
}

Compilation message

boat.cpp: In function 'std::vector<std::pair<int, int> > compress(std::vector<std::pair<int, int> >&)':
boat.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
boat.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if (i + 1 != v.size() && v[i] + 1 <= v[i + 1] - 1) grids.emplace_back(v[i] + 1, v[i + 1] - 1);
      |             ~~~~~~^~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < grid.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
boat.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0; i < grid.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
boat.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int j = 0; j < grid.size(); j++) {
      |                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 427 ms 8176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 427 ms 8176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 427 ms 8176 KB Output isn't correct
2 Halted 0 ms 0 KB -