Submission #53347

#TimeUsernameProblemLanguageResultExecution timeMemory
53347junodeveloperBoat (APIO16_boat)C++11
100 / 100
1059 ms11052 KiB
#include <bits/stdc++.h> #define SZ(x) ((int)x.size()) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; const int MOD = 1e9 + 7; int n, a[510], b[510]; int dp[510][1010], dp2[510][1010]; int sum[1010][510], scnt[1010][510], fac[510]={1}, inv[510]={1}, bigfac[1010][510]; vector<int> Vx; int modpow(int a, long long n, int mod = MOD) { int r = 1, b = a; while(n > 0) { if(n & 1) r = 1ll * r * b % mod; b = 1ll * b * b % mod; n >>= 1; } return r; } int main() { scanf("%d", &n); for(int i=1; i<=n; i++) { scanf("%d%d", a+i, b+i); b[i]++; Vx.push_back(a[i]); Vx.push_back(b[i]); } sort(ALL(Vx)); Vx.erase(unique(ALL(Vx)), Vx.end()); for(int i=1; i<=500; i++) { fac[i] = 1ll * fac[i-1] * i % MOD; inv[i] = modpow(fac[i], MOD - 2); } for(int i=1; i<SZ(Vx); i++) { int len = Vx[i] - Vx[i-1]; bigfac[i][0] = 1; for(int j=1; j<=n; j++) { scnt[i][j] = scnt[i][j-1] + (min(b[j], Vx[i]) - max(a[j], Vx[i-1]) > 0); bigfac[i][j] = 1ll * bigfac[i][j-1] * (len - j + 1) % MOD; } for(int j=1; j<=scnt[i][n]; j++) for(int k=1; k<=j; k++) sum[i][j] = (sum[i][j] + 1ll * fac[j-1] * inv[k-1] % MOD * inv[j-k] % MOD * bigfac[i][k] % MOD * inv[k]) % MOD; } int res = 0; for(int i=1; i<=n; i++) { for(int j=1; j<SZ(Vx); j++) { if(!(min(b[i], Vx[j]) - max(a[i], Vx[j-1]) > 0)) continue; dp[i][j] = sum[j][scnt[j][i]]; for(int k=1; k<i; k++) dp[i][j] = (dp[i][j] + 1ll * dp2[k][j-1] * sum[j][scnt[j][i] - scnt[j][k]]) % MOD; res = (res + dp[i][j]) % MOD; } for(int j=1; j<SZ(Vx); j++) dp2[i][j] = (dp2[i][j-1] + dp[i][j]) % MOD; } // sum[s][cnt] : sum(C(cnt-1, i-1) * C(Vx[s]-Vx[s-1], i)) for 1<=i<=cnt printf("%d", res); return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
boat.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", a+i, b+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...