Submission #1085963

#TimeUsernameProblemLanguageResultExecution timeMemory
1085963quanlt206Boat (APIO16_boat)C++17
0 / 100
3 ms4444 KiB
#include<bits/stdc++.h> #define X first #define Y second #define all(x) begin(x), end(x) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORD(i, b, a) for(int i = (b); i >= (a); i--) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define mxx max_element #define mnn min_element #define SQR(x) (1LL * (x) * (x)) #define MASK(i) (1LL << (i)) #define Point Vector #define left Left #define right Right #define div Div using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<db, db> pdb; typedef pair<ld, ld> pld; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; typedef pair<ll, int> pli; typedef pair<ll, pii> plii; template<class A, class B> bool maximize(A& x, B y) { if (x < y) return x = y, true; else return false; } template<class A, class B> bool minimize(A& x, B y) { if (x > y) return x = y, true; else return false; } /* END OF TEMPLATE */ const int N = 1e3 + 7; const int mod = 1e9 + 7; int n, m, a[N], b[N]; vector<int> E; pii block[N]; int dp[N][N]; void add(int& x, int y) { if ((x+=y) >= mod) x-=mod; } int Ckn[N][N]; long long fact[N], inv_fact[N]; long long mul(long long a, long long b) { if (b == 0) return 1; ll tmp = mul(a, b / 2); tmp = tmp * tmp % mod; if (b & 1) tmp = tmp * a % mod; return tmp; } void buildCkn() { fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod; inv_fact[n] = mul(fact[n], mod - 2); for (int i = n - 1; i > 0; i--) inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod; for (int i = 1; i <= m; i++) { int sz = block[i].Y - block[i].X + 1; ll tich = 1; for (int j = sz; j > 0; j--) { tich = tich * j % mod; Ckn[i][sz - j + 1] = tich * inv_fact[sz - j + 1] % mod; if (sz - j + 1 > n) break; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; set<int> s; for (int i = 1; i <= n; i++) { cin>>a[i]>>b[i]; s.insert(a[i]); s.insert(b[i]); } vector<int> E(s.begin(), s.end()); m = E.size(); for (int i = 0; i + 1< E.size(); i++) block[i + 1] = {E[i], E[i + 1] - 1}; block[m] = {E[m - 1], E[m - 1]}; buildCkn(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = dp[i - 1][j]; add(dp[i][j], dp[i][j - 1]); if (a[i] <= block[j].X && block[j].Y <= b[i]) { add(dp[i][j], 1); for (int k = i - 1; k >= 1; k--) if (!(a[k] <= block[j].X && block[j].Y <= b[k]) || (block[j].Y - block[j].X + 1 < i - k + 1)) break; else { add(dp[i][j], 1LL * dp[k - 1][j - 1] * Ckn[j][i - k + 1] % mod); } } } } // cout<<dp[1][1]<<" "<<dp[1][2]<<" "<<dp[1][3]<<"\n"; cout<<dp[n][m]; return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:100:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for (int i = 0; i + 1< E.size(); i++) block[i + 1] = {E[i], E[i + 1] - 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...