Submission #349289

#TimeUsernameProblemLanguageResultExecution timeMemory
349289denkendoemeerBoat (APIO16_boat)C++14
100 / 100
1451 ms4480 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; #define mod 1000000007 vector<int>aux; array<int,2>v[505]; ll dp[1005][505],inv[505]; int main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); int n,i,j,e; scanf("%d",&n); aux={-1}; inv[1]=1; for(i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod; for(i=1;i<=n;i++){ scanf("%d%d",&v[i][0],&v[i][1]); ++v[i][1]; aux.push_back(v[i][0]); aux.push_back(v[i][1]); } sort(aux.begin(),aux.end()); aux.resize(unique(aux.begin(),aux.end())-aux.begin()); int m=aux.size(); for(i=0;i<m;i++) dp[i][0]=1; for(i=1;i<=n;i++){ for(j=m-1;j>=1;j--) if (v[i][0]<=aux[j-1] && aux[j]<=v[i][1]){ int cnt=aux[j]-aux[j-1]; for(e=min(cnt,i);e>=1;e--) dp[j][e]=(dp[j][e]+dp[j][e-1]*(cnt-e+1)%mod*inv[e])%mod; } for(j=1;j<=m;j++){ dp[j][0]=0; for(e=0;e<=n;e++) dp[j][0]=(dp[j][0]+dp[j-1][e])%mod; } } printf("%lld\n",(dp[m][0]+mod-1)%mod); return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |         scanf("%d%d",&v[i][0],&v[i][1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...