Submission #417887

#TimeUsernameProblemLanguageResultExecution timeMemory
417887erfanmirBoat (APIO16_boat)C++17
100 / 100
816 ms4480 KiB
// In the name of god #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template < class T > using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define all(x) (x).begin(),(x).end() #define lc(x) (x) << 1 #define rc(x) (x) << 1 | 1 #define F first #define S second #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout); #define mp make_pair ll poww(ll a, ll b, ll md) { ll ans = 1; for(; b; b >>= 1, a = a * a % md){ if(b & 1){ ans = ans * a % md; } } return ans % md; } const int MAXN = 1000 + 10; const int MAXLG = 18; const int MOD = 1e9 + 7; const int MOD2 = 998244353; const ll INF = 8e18; int n, a[MAXN], b[MAXN]; vector<int> vec; ll dp[MAXN][MAXN], x[MAXN], ans, inv[MAXN]; int main() { scanf("%d", &n); for(int i = 0; i <= n; i++){ inv[i] = poww(i, MOD - 2, MOD); } for(int i = 1; i <= n; i++){ scanf("%d %d", a + i, b + i); b[i]++; vec.push_back(b[i]); vec.push_back(a[i]); } sort(all(vec)); vec.erase(unique(all(vec)), vec.end()); for(int i = 1; i < (int)vec.size(); i++){ x[i] = vec[i] - vec[i - 1]; } for(int i = 1; i <= n; i++){ a[i] = lower_bound(all(vec), a[i]) - vec.begin(); b[i] = lower_bound(all(vec), b[i]) - vec.begin(); } for(int i = 0; i < (int)vec.size(); i++){ dp[0][i] = 1; } for(int i = 1; i <= n; i++){ for(int j = 1; j < (int)vec.size(); j++){ if(!(a[i] < j && b[i] >= j)){ continue; } ll tmp = x[j], kmp = x[j], vlc = 1; for(int k = i - 1; k >= 0; k--){ dp[i][j] += (dp[k][j - 1] * tmp) % MOD; dp[i][j] %= MOD; if(a[k] < j && b[k] >= j){ kmp++; vlc++; kmp %= MOD; vlc %= MOD; tmp *= (kmp * inv[vlc]) % MOD; tmp %= MOD; } } //printf(":: %d %d %lld\n", i, j, dp[i][j]); } for(int j = 1; j < (int)vec.size();j++){ dp[i][j] += dp[i][j - 1]; dp[i][j] %= MOD; } } for(int i = 1; i <= n; i++){ ans += dp[i][(int)vec.size() - 1]; ans %= MOD; } printf("%lld\n", ans); }

Compilation message (stderr)

boat.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    3 | #pragma comment(linker, "/stack:200000000")
      | 
boat.cpp: In function 'int main()':
boat.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         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...