답안 #43326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43326 2018-03-13T15:01:18 Z nonocut Boat (APIO16_boat) C++14
9 / 100
20 ms 700 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], sum[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());
    pos.erase(unique(pos.begin(),pos.end()),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;
            sum[x] = add(sum[x-1], dp[x]);
            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(len, sum[x-1]));
                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;
}

ll solve2() {
    ll ans = 0;
    for(int i=1;i<=n;i++) {
        dp[i] = 1;
        for(int j=1;j<i;j++) {
            if(a[i]>a[j]) dp[i] = add(dp[i], dp[j]);
        }
        ans = add(ans, dp[i]);
    }
    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:81:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
boat.cpp:82: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 Correct 10 ms 376 KB Output is correct
2 Correct 11 ms 376 KB Output is correct
3 Correct 12 ms 424 KB Output is correct
4 Correct 12 ms 440 KB Output is correct
5 Correct 10 ms 440 KB Output is correct
6 Correct 10 ms 516 KB Output is correct
7 Correct 12 ms 572 KB Output is correct
8 Correct 12 ms 572 KB Output is correct
9 Correct 11 ms 700 KB Output is correct
10 Correct 10 ms 700 KB Output is correct
11 Correct 11 ms 700 KB Output is correct
12 Correct 11 ms 700 KB Output is correct
13 Correct 10 ms 700 KB Output is correct
14 Correct 10 ms 700 KB Output is correct
15 Correct 11 ms 700 KB Output is correct
16 Correct 3 ms 700 KB Output is correct
17 Correct 4 ms 700 KB Output is correct
18 Correct 3 ms 700 KB Output is correct
19 Correct 3 ms 700 KB Output is correct
20 Correct 3 ms 700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 376 KB Output is correct
2 Correct 11 ms 376 KB Output is correct
3 Correct 12 ms 424 KB Output is correct
4 Correct 12 ms 440 KB Output is correct
5 Correct 10 ms 440 KB Output is correct
6 Correct 10 ms 516 KB Output is correct
7 Correct 12 ms 572 KB Output is correct
8 Correct 12 ms 572 KB Output is correct
9 Correct 11 ms 700 KB Output is correct
10 Correct 10 ms 700 KB Output is correct
11 Correct 11 ms 700 KB Output is correct
12 Correct 11 ms 700 KB Output is correct
13 Correct 10 ms 700 KB Output is correct
14 Correct 10 ms 700 KB Output is correct
15 Correct 11 ms 700 KB Output is correct
16 Correct 3 ms 700 KB Output is correct
17 Correct 4 ms 700 KB Output is correct
18 Correct 3 ms 700 KB Output is correct
19 Correct 3 ms 700 KB Output is correct
20 Correct 3 ms 700 KB Output is correct
21 Incorrect 20 ms 700 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 376 KB Output is correct
2 Correct 11 ms 376 KB Output is correct
3 Correct 12 ms 424 KB Output is correct
4 Correct 12 ms 440 KB Output is correct
5 Correct 10 ms 440 KB Output is correct
6 Correct 10 ms 516 KB Output is correct
7 Correct 12 ms 572 KB Output is correct
8 Correct 12 ms 572 KB Output is correct
9 Correct 11 ms 700 KB Output is correct
10 Correct 10 ms 700 KB Output is correct
11 Correct 11 ms 700 KB Output is correct
12 Correct 11 ms 700 KB Output is correct
13 Correct 10 ms 700 KB Output is correct
14 Correct 10 ms 700 KB Output is correct
15 Correct 11 ms 700 KB Output is correct
16 Correct 3 ms 700 KB Output is correct
17 Correct 4 ms 700 KB Output is correct
18 Correct 3 ms 700 KB Output is correct
19 Correct 3 ms 700 KB Output is correct
20 Correct 3 ms 700 KB Output is correct
21 Incorrect 20 ms 700 KB Output isn't correct
22 Halted 0 ms 0 KB -