Submission #152816

#TimeUsernameProblemLanguageResultExecution timeMemory
152816arnold518Boat (APIO16_boat)C++14
0 / 100
11 ms4344 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1000; const ll MOD = 1e9+7; int N, S, A[MAXN+10], B[MAXN+10]; vector<int> comp; ll inv[MAXN+10], dp[MAXN+10][MAXN+10], ans; int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin(); } ll pow(ll x, ll y) { if(y==0) return 1; if(y%2) return pow(x, y-1)*x%MOD; ll t=pow(x, y/2); return t*t%MOD; } int main() { int i, j, k; for(i=1; i<=MAXN; i++) inv[i]=pow(i, MOD-2); scanf("%d", &N); for(i=1; i<=N; i++) { scanf("%d%d", &A[i], &B[i]); B[i]++; comp.push_back(A[i]); comp.push_back(B[i]); } comp.push_back(0); sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); S=comp.size()-1; for(i=0; i<S; i++) dp[0][i]=1; for(i=1; i<=N; i++) { dp[i][0]=dp[i-1][S-1]; for(j=getcomp(A[i]); j<getcomp(B[i]); j++) { ll bino=1; ll sz=comp[j+1]-comp[j]; for(k=1; k<=i; k++) { if(k>sz) break; bino=bino*(sz-k+1)%MOD; bino=bino*inv[k]%MOD; dp[i][j]+=dp[i-k][j-1]*bino%MOD; dp[i][j]%=MOD; } } for(j=1; j<S; j++) dp[i][j]+=dp[i][j-1], dp[i][j]%=MOD; } ans=dp[N][S-1]-1; if(ans<0) ans+=MOD; printf("%lld", ans); }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
boat.cpp:34: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...