Submission #448068

#TimeUsernameProblemLanguageResultExecution timeMemory
448068urd05Boat (APIO16_boat)C++17
100 / 100
496 ms332 KiB
#include <bits/stdc++.h> using namespace std; vector<int> press; int n; typedef pair<int,int> P; P arr[501]; long long psum[501]; long long save[501]; const int mod=1e9+7; long long value[501]; long long fastpow(long long a,long long b) { if (b==0) { return 1; } if (b%2==1) { return (fastpow(a,b-1)*a)%mod; } long long half=fastpow(a,b/2); return (half*half)%mod; } int main(void) { scanf("%d",&n); press.push_back(1); for(int i=1;i<=n;i++) { int a,b; scanf("%d %d",&a,&b); arr[i]=P(a,b); press.push_back(a); press.push_back(b+1); } sort(press.begin(),press.end()); press.erase(unique(press.begin(),press.end()),press.end()); for(int i=1;i<=n;i++) { arr[i].first=lower_bound(press.begin(),press.end(),arr[i].first)-press.begin()+1; arr[i].second=lower_bound(press.begin(),press.end(),arr[i].second+1)-press.begin(); } for(int i=0;i<n;i++) { psum[i]=1; } for(int i=1;i<press.size();i++) { int sz=press[i]-press[i-1]; value[0]=sz; for(int j=1;j<=n;j++) { value[j]=(value[j-1]*(sz+j))%mod; value[j]*=fastpow(j+1,mod-2); value[j]%=mod; } vector<long long> v; save[0]=0; for(int j=1;j<=n;j++) { if (arr[j].first<=i&&i<=arr[j].second) { v.insert(v.begin(),psum[j-1]); } save[j]=0; for(int k=0;k<v.size();k++) { save[j]+=(value[k]*v[k])%mod; save[j]%=mod; } } for(int j=0;j<=n;j++) { //printf("%lld ",save[j]); psum[j]+=save[j]; psum[j]%=mod; } //printf("\n"); } printf("%lld",psum[n]); }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=1;i<press.size();i++) {
      |                 ~^~~~~~~~~~~~~
boat.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             for(int k=0;k<v.size();k++) {
      |                         ~^~~~~~~~~
boat.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...