답안 #91045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91045 2018-12-26T01:29:20 Z RezwanArefin01 Boat (APIO16_boat) C++17
0 / 100
7 ms 4472 KB
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

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

int n, a[N], b[N], len[N], dp[N][N], inv[N]; 
map<int, int> com;

void add(int &a, int b) {
    a += b; if(a >= mod) a -= mod; 
}

int main(int argc, char const *argv[]) {
    inv[1] = 1; 
    for(int i = 2; i < N; i++) {
        inv[i] =  -(mod / i) * (ll) inv[mod % i] % mod; 
        inv[i] += mod; 
    }

    scanf("%d", &n);
    vector<int> v; 

    for(int i = 1; i <= n; i++) {
        scanf("%d %d", &a[i], &b[i]); b[i]++; 
        v.push_back(a[i]); 
        v.push_back(b[i]); 
    } 
    sort(v.begin(), v.end()); 
    v.erase(unique(v.begin(), v.end()), v.end()); 

    for(int i = 0; i < v.size(); i++) com[v[i]] = i + 1;
    for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1]; 
    for(int i = 1; i <= n; i++) a[i] = com[a[i]], b[i] = com[b[i]]; 
    
    int m = v.size() - 1; 
    dp[0][0] = 1; 
        
    for(int k = 1; k <= m; k++) { dp[k][0] = 1; 
        for(int i = 1; i <= n; i++) {
            dp[k][i] = dp[k - 1][i]; 
            if(k < a[i] || k >= b[i]) continue; 

            int cnt = 1, prod = len[i];
            for(int j = i - 1; j >= 0; j--) {
                add(dp[k][i], (ll) prod * dp[k - 1][j] % mod); 
                if(a[j] <= k && k < b[j]) {
                    prod = (ll) prod * (cnt + len[k]) % mod * inv[++cnt] % mod;  
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) 
        add(ans, dp[m][i]); 
    printf("%d\n", ans); 
}  

Compilation message

boat.cpp: In function 'int main(int, const char**)':
boat.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v.size(); i++) com[v[i]] = i + 1;
                    ~~^~~~~~~~~~
boat.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1]; 
                    ~~^~~~~~~~~~
boat.cpp:52:67: warning: operation on 'cnt' may be undefined [-Wsequence-point]
                     prod = (ll) prod * (cnt + len[k]) % mod * inv[++cnt] % mod;  
                                                                   ^~~~~
boat.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a[i], &b[i]); b[i]++; 
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -