Submission #109547

#TimeUsernameProblemLanguageResultExecution timeMemory
109547PeppaPigBoat (APIO16_boat)C++14
0 / 100
11 ms2304 KiB
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 505; const int M = 1e9+7; long fac[N], inv[N]; long modpow(long a, long b) { long ret = 1; for( ; b; b >>= 1) { if(b & 1) ret = (ret * a) % M; a = (a * a) % M; } return ret; } void pre_process() { fac[0] = inv[0] = 1; for(int i = 1; i < N; i++) fac[i] = (fac[i-1] * i) % M; for(int i = 1; i < N; i++) inv[i] = modpow(fac[i], M-2); } long ncr(int n, int r) { return fac[n] * (inv[r] * inv[n-r] % M) % M; } int n, a[N], b[N]; long dp[N][N]; vector<int> coord; int main() { pre_process(); scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d %d", a+i, b+i); coord.emplace_back(a[i]); coord.emplace_back(++b[i]); } sort(coord.begin(), coord.end()); coord.resize(unique(coord.begin(), coord.end()) - coord.begin()); for(int i = 1; i <= n; i++) { a[i] = lower_bound(coord.begin(), coord.end(), a[i]) - coord.begin() + 1; b[i] = lower_bound(coord.begin(), coord.end(), b[i]) - coord.begin() + 1; } for(int i = 0; i < coord.size(); i++) dp[0][i] = 1; for(int i = 1; i <= n; i++) { for(int j = a[i]; j < b[i]; j++) for(int k = i-1, cnt = 1; ~k; k--) { dp[i][j] += (ncr(coord[j] - coord[j-1] + cnt - 1, cnt) * dp[k][j-1]) % M; dp[i][j] %= M; if(a[k] <= j && j < b[k]) ++cnt; } for(int j = 1; j < coord.size(); j++) dp[i][j] = (dp[i][j] + dp[i][j-1]) % M; } long ans = 0; for(int i = 1; i <= n; i++) ans = (ans + dp[i][coord.size()-1]) % M; printf("%lld\n", ans); return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < coord.size(); i++) dp[0][i] = 1;
                    ~~^~~~~~~~~~~~~~
boat.cpp:54:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1; j < coord.size(); j++) dp[i][j] = (dp[i][j] + dp[i][j-1]) % M;
                        ~~^~~~~~~~~~~~~~
boat.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", a+i, b+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...