Submission #400058

#TimeUsernameProblemLanguageResultExecution timeMemory
400058juggernautBoat (APIO16_boat)C++17
100 / 100
1444 ms4296 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...) #endif #define mod 1000000007 vector<int>aux; array<int,2>v[505]; ll dp[1005][505],inv[505]; int main(){ 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); }

Compilation message (stderr)

boat.cpp: In function 'void usaco(std::string)':
boat.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |         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...