Submission #85390

#TimeUsernameProblemLanguageResultExecution timeMemory
85390popovicirobertBoat (APIO16_boat)C++14
9 / 100
21 ms2972 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long using namespace std; const int MOD = (int) 1e9 + 7; const int MAXN = 500; inline int lgput(int a, int b) { int ans = 1; while(b > 0) { if(b & 1) ans = (1LL * ans * a) % MOD; b >>= 1; a = (1LL * a * a) % MOD; } return ans; } inline void mod(int &x) { if(x >= MOD) x -= MOD; } int dp[MAXN + 1][2 * MAXN + 1]; int main() { //ifstream cin("C.in"); //ofstream cout("C.out"); int i, j, n; ios::sync_with_stdio(false); cin >> n; vector <int> a(n + 1), b(n + 1); vector <int> nrm; for(i = 1; i <= n; i++) { cin >> a[i] >> b[i]; b[i]++; nrm.push_back(a[i]); nrm.push_back(b[i]); } sort(nrm.begin(), nrm.end()); nrm.resize(unique(nrm.begin(), nrm.end()) - nrm.begin()); for(i = 1; i <= n; i++) { a[i] = lower_bound(nrm.begin(), nrm.end(), a[i]) - nrm.begin(); b[i] = lower_bound(nrm.begin(), nrm.end(), b[i]) - nrm.begin(); } vector <int> inv(n + 1); for(i = 1; i <= n; i++) { inv[i] = lgput(i, MOD - 2); } vector <int> len(2 * n); for(i = 0; i < nrm.size(); i++) { if(i + 1 < nrm.size()) { len[i] = nrm[i + 1] - nrm[i]; } dp[0][i] = 1; } for(i = 1; i <= n; i++) { dp[i][0] = 1; for(j = a[i] + 1; j <= b[i]; j++) { dp[i][j] = (1LL * dp[i - 1][j - 1] * len[j - 1]) % MOD; int coef = len[j - 1]; int nr = 1; for(int p = i - 2; p >= 0; p--) { if(a[p + 1] < j && j <= b[p + 1]) { nr++; if(nr > len[j - 1]) { break; } // comb(len + nr - 2, nr) coef = (1LL * coef * (len[j - 1] + nr - 2)) % MOD; coef = (1LL * coef * inv[nr]) % MOD; dp[i][j] = (dp[i][j] + 1LL * coef * dp[p][j - 1]) % MOD; } } } for(j = 1; j < nrm.size(); j++) { dp[i][j] = (1LL * dp[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD; } } cout << (dp[n][nrm.size() - 1] - 1 + MOD) % MOD; //cin.close(); //cout.close(); return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i = 0; i < nrm.size(); i++) {
                ~~^~~~~~~~~~~~
boat.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i + 1 < nrm.size()) {
            ~~~~~~^~~~~~~~~~~~
boat.cpp:78:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j = 1; j < nrm.size(); j++) {
                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...