Submission #640385

#TimeUsernameProblemLanguageResultExecution timeMemory
640385imtoreBoat (APIO16_boat)C++17
9 / 100
72 ms2348 KiB
#include <stdio.h> #include <vector> #include <algorithm> #define ll long long #define MOD 1'000'000'007 using namespace std; int A[521], B[521]; vector<int> X; ll inv[521]; ll dp1[521], dp2[521][521], sum[521]; ll get_inv(ll x, ll y = MOD-2){ ll z = y & 1 ? x : 1; while(y >>= 1){ if(y & 1) z = z*x%MOD; x = x*x%MOD; } return z; } int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d %d", &A[i], &B[i]); for(int i = 1; i <= n; i++){ X.push_back(A[i]); X.push_back(B[i]+1); } sort(X.begin(), X.end()); X.erase(unique(X.begin(), X.end()), X.end()); for(int i = 1; i <= n; i++){ A[i] = lower_bound(X.begin(), X.end(), A[i])-X.begin()+1; B[i] = lower_bound(X.begin(), X.end(), B[i]+1)-X.begin(); } for(int i = 1; i <= n; i++) inv[i] = get_inv(i); dp1[0] = 1; for(int i = 1; i < X.size(); i++){ for(int j = 0; j <= n; j++) dp2[j][0] = dp1[j]; fill(sum, sum+n+1, 0); int cnt = 0; sum[0] = dp2[0][0]; for(int j = 1; j <= n; j++){ if(A[j] <= i && B[j] >= i){ int l = X[i]-X[i-1]; cnt++; for(int k = min(cnt, l); k >= 1; k--){ dp2[j][k] = sum[k-1]*(l-k+1)%MOD*inv[k]%MOD; sum[k] = (sum[k]+dp2[j][k])%MOD; } } sum[0] = (sum[0]+dp2[j][0])%MOD; } /* printf("%d\n", i); for(int j = 0; j <= n; j++){ for(int k = 0; k <= min(cnt, X[i]-X[i-1]); k++) printf("%lld ", dp2[j][k]); printf("\n"); } printf("\n"); */ cnt = 0; for(int j = 1; j <= n; j++){ dp1[j] = dp2[j][0]; if(A[j] <= i && B[j] >= i){ cnt++; for(int k = 1; k <= cnt; k++) dp1[j] = (dp1[j]+dp2[j][k])%MOD; } } } ll ans = 0; for(int i = 1; i <= n; i++) ans = (ans+dp1[i])%MOD; printf("%lld", ans); return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:43:19: 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 < X.size(); i++){
      |                 ~~^~~~~~~~~~
boat.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
boat.cpp:26:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  for(int i = 1; i <= n; i++) 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...