Submission #47257

# Submission time Handle Problem Language Result Execution time Memory
47257 2018-04-29T18:33:10 Z ngkan146 Boat (APIO16_boat) C++11
9 / 100
2000 ms 3240 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = (ll) 1e9+7;
int n, a[505], b[505];
ll f[505][3005];
ll g[505];

int main(){
    iostream::sync_with_stdio(0);
    cin >> n;
    vector <int> lst;
    for(int i=1;i<=n;i++)
        cin >> a[i] >> b[i],
        lst.push_back(a[i]),
        lst.push_back(b[i]);
    sort(lst.begin(), lst.end());
    lst.resize(unique(lst.begin(),lst.end()) - lst.begin());
    vector <pair<int,int> > range;
    for(int i=0;i<lst.size();i++){
        range.push_back({lst[i], lst[i]});
        if (i != lst.size() - 1 && lst[i]+1 <= lst[i+1]-1)
            range.push_back({lst[i]+1, lst[i+1]-1});
    }
    range.insert(range.begin(), {-1,-1});
    g[0] = 1;
    ll ans = 0;
    for(int j = 1;j < range.size();j ++){
        // f[i][j] = cnt of way that end at i and value of i in range j
        int len = range[j].second - range[j].first + 1;
        ll arr[505];
        arr[0] = 1;

        for(int i=1;i<=n;i++)
            arr[i] = arr[i-1] * (len+1-i) % mod;

        for(int i=1;i<=n;i++){
            if (range[j].first < a[i] || b[i] < range[j].second)
                continue;
            int possiBoat = 0;

            for(int ii=i;ii>=1;ii--){
                if (!(a[ii] <= range[j].first && range[j].second <= b[ii]))  continue;
                possiBoat += (a[ii] <= range[j].first && range[j].second <= b[ii]);
                if (possiBoat > len)    break;
                for(int iii=ii-1;iii>=0;iii--){
                    for(int cnt=1;cnt<=possiBoat;cnt++){
                        f[i][j] = (f[i][j] + g[iii] * arr[cnt] % mod) % mod;
                    }
                }
            }
            ans = (ans + f[i][j]) % mod;
        }
        for(int i=0;i<=n;i++){
            g[i] = (g[i] + f[i][j]) % mod;
        }
    }
    cout << ans;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<lst.size();i++){
                 ~^~~~~~~~~~~
boat.cpp:22:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i != lst.size() - 1 && lst[i]+1 <= lst[i+1]-1)
             ~~^~~~~~~~~~~~~~~~~
boat.cpp:28:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 1;j < range.size();j ++){
                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2296 KB Output is correct
2 Correct 12 ms 2404 KB Output is correct
3 Correct 12 ms 2596 KB Output is correct
4 Correct 12 ms 2596 KB Output is correct
5 Correct 12 ms 2620 KB Output is correct
6 Correct 12 ms 2632 KB Output is correct
7 Correct 12 ms 2652 KB Output is correct
8 Correct 12 ms 2684 KB Output is correct
9 Correct 12 ms 2692 KB Output is correct
10 Correct 11 ms 2804 KB Output is correct
11 Correct 13 ms 2816 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 13 ms 2816 KB Output is correct
14 Correct 12 ms 2816 KB Output is correct
15 Correct 12 ms 2816 KB Output is correct
16 Correct 7 ms 2836 KB Output is correct
17 Correct 6 ms 2848 KB Output is correct
18 Correct 7 ms 2860 KB Output is correct
19 Correct 6 ms 2872 KB Output is correct
20 Correct 7 ms 2880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2296 KB Output is correct
2 Correct 12 ms 2404 KB Output is correct
3 Correct 12 ms 2596 KB Output is correct
4 Correct 12 ms 2596 KB Output is correct
5 Correct 12 ms 2620 KB Output is correct
6 Correct 12 ms 2632 KB Output is correct
7 Correct 12 ms 2652 KB Output is correct
8 Correct 12 ms 2684 KB Output is correct
9 Correct 12 ms 2692 KB Output is correct
10 Correct 11 ms 2804 KB Output is correct
11 Correct 13 ms 2816 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 13 ms 2816 KB Output is correct
14 Correct 12 ms 2816 KB Output is correct
15 Correct 12 ms 2816 KB Output is correct
16 Correct 7 ms 2836 KB Output is correct
17 Correct 6 ms 2848 KB Output is correct
18 Correct 7 ms 2860 KB Output is correct
19 Correct 6 ms 2872 KB Output is correct
20 Correct 7 ms 2880 KB Output is correct
21 Execution timed out 2069 ms 3240 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 269 ms 3240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2296 KB Output is correct
2 Correct 12 ms 2404 KB Output is correct
3 Correct 12 ms 2596 KB Output is correct
4 Correct 12 ms 2596 KB Output is correct
5 Correct 12 ms 2620 KB Output is correct
6 Correct 12 ms 2632 KB Output is correct
7 Correct 12 ms 2652 KB Output is correct
8 Correct 12 ms 2684 KB Output is correct
9 Correct 12 ms 2692 KB Output is correct
10 Correct 11 ms 2804 KB Output is correct
11 Correct 13 ms 2816 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 13 ms 2816 KB Output is correct
14 Correct 12 ms 2816 KB Output is correct
15 Correct 12 ms 2816 KB Output is correct
16 Correct 7 ms 2836 KB Output is correct
17 Correct 6 ms 2848 KB Output is correct
18 Correct 7 ms 2860 KB Output is correct
19 Correct 6 ms 2872 KB Output is correct
20 Correct 7 ms 2880 KB Output is correct
21 Execution timed out 2069 ms 3240 KB Time limit exceeded
22 Halted 0 ms 0 KB -