Submission #111222

# Submission time Handle Problem Language Result Execution time Memory
111222 2019-05-14T10:35:08 Z tictaccat Boat (APIO16_boat) C++14
0 / 100
21 ms 16876 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAX = 500 + 5;
const int MOD = 1e9 + 7;
const int INV2 = 5e8 + 4;

int N,ans;
vector<int> a(MAX), b(MAX), ways(2*MAX), newWays(2*MAX), bin; //ways[i] = ways of ending between bin[i] and bin[i+1]-1
vector<vector<int>> Z(MAX), mem(MAX*2,vector<int>(MAX*2,-1));

int choose(int n, int k) {
    if (k > n) return 0;
    if (k == 0) return 1;
    if (mem[n][k] != -1) return mem[n][k];
    int temp = (choose(n-1,k-1) + choose(n-1,k)) % MOD;
    return mem[n][k] = temp;
}

int calc(int sz, vector<int> z) {
    int res = 0;
    for (int i = 1; i <= z.size(); i++) {
        res += choose(sz+i-1,i) * z[z.size()-i] % MOD;
        res %= MOD;
    }
    return res;
}

main() {

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
        b[i]++;
        bin.push_back(a[i]);
        bin.push_back(b[i]);
    }

    sort(bin.begin(),bin.end());
    bin.erase(unique(bin.begin(),bin.end()),bin.end());

    for (int i = 0; i < N; i++) {
        int pre = 1, k = 0; 
        for (; bin[k] < a[i]; k++) {pre += ways[k]; pre %= MOD;}
        for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
            int sz = bin[k+1] - bin[k];
            Z[k].push_back(pre);
            newWays[k] = calc(sz,Z[k]);
            pre += ways[k];
            pre %= MOD;
        }
        ways = newWays;
    }

    for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]*(bin[k+1]-bin[k]); ans %= MOD;}

    cout << (ans < 0 ? ans + MOD : ans) << "\n";

    return 0;
}

Compilation message

boat.cpp: In function 'long long int calc(long long int, std::vector<long long int>)':
boat.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i <= z.size(); i++) {
                     ~~^~~~~~~~~~~
boat.cpp: At global scope:
boat.cpp:32:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
boat.cpp: In function 'int main()':
boat.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
                ~~~~^~~~~~~~~~~~
boat.cpp:59:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]*(bin[k+1]-bin[k]); ans %= MOD;}
                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 16640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 16640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 16876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 16640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -