답안 #43323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43323 2018-03-13T14:50:14 Z nonocut Boat (APIO16_boat) C++14
0 / 100
36 ms 500 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second

const int maxn = 2e3 + 5;
const ll mod = 1e9 + 7;

int n;
int a[maxn], b[maxn];
vector<int> pos;
int sz;
pii itv[maxn];
ll dp[maxn], temp[maxn];

ll add(ll x, ll y) {
    return ((x+y)%mod + mod)%mod;
}
ll mul(ll x, ll y) {
    return ((x*y)%mod + mod)%mod;
}
ll inv(ll a, ll b){
    return 1<a ? b - inv(b%a,a)*b/a : 1;
}

void show(int key) {
    printf("show %d\n",key);
    for(int i=1;i<=sz;i++) printf("---- [%d, %d] : %lld\n",itv[i].X,itv[i].Y,dp[i]);
}

void init() {
    pos.pb(0); pos.pb(2e9);
    for(int i=1;i<=n;i++) pos.pb(a[i]), pos.pb(b[i]);
    sort(pos.begin(),pos.end());
    unique(pos.begin(),pos.end());
    for(int i=0;i<pos.size()-1;i++) {
        itv[++sz] = {pos[i],pos[i]};
        if(pos[i]+1<=pos[i+1]-1) itv[++sz] = {pos[i]+1,pos[i+1]-1};
    }
//    show(0);
}

ll solve() {
    dp[1] = 1;
    for(int cur=1;cur<=n;cur++) {
        for(int x=1;x<=sz;x++) {
            temp[x] = 0;
            if(a[cur]<=itv[x].X && itv[x].Y<=b[cur]) {
                int len = itv[x].Y-itv[x].X+1;
                for(int y=1;y<x;y++) temp[x] = add(temp[x], mul(len, dp[y]));
                temp[x] = add(temp[x], (mul(mul(len-1, inv(2,mod)), dp[x])));
            }
        }
        for(int x=1;x<=sz;x++) dp[x] = add(dp[x], temp[x]);
//        show(cur);
    }
    ll ans = 0;
    for(int x=2;x<=sz;x++) ans = add(ans, dp[x]);
    return ans;
}

int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    init();
    printf("%lld",solve());
}

Compilation message

boat.cpp: In function 'void init()':
boat.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<pos.size()-1;i++) {
                  ^
boat.cpp: In function 'int main()':
boat.cpp:67:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
boat.cpp:68:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
                                                    ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -