Submission #143028

#TimeUsernameProblemLanguageResultExecution timeMemory
143028HellAngelBoat (APIO16_boat)C++14
9 / 100
419 ms12336 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 1007; const int somod = 1e9 + 7; int n, m, a[maxn], b[maxn]; int precal[maxn][maxn], s[maxn][maxn]; vector<int> vt; int BIT[maxn], ans[maxn], dp[maxn][maxn], total[maxn]; int Pow(int i, int j) { if(j == 0) return 1; int mid = Pow(i, j / 2); mid = mid * mid % somod; if(j & 1) mid = mid * i % somod; return mid; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout); cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; vt.push_back(a[i]); vt.push_back(b[i] + 1); } sort(vt.begin(), vt.end()); vt.erase(unique(vt.begin(), vt.end()), vt.end()); int k = vt.size(); k--; for(int i = 1; i <= k; i++) { precal[i][0] = 1; int Dist = vt[i] - vt[i - 1]; precal[i][1] = Dist; for(int j = 2; j <= n + 1; j++) { precal[i][j] = precal[i][j - 1] * (Dist + j - 1) % somod * Pow(j, somod - 2) % somod; ///figurate number } } for(int i = 1; i <= n; i++) { int sum = 0; for(int j = 1; j <= k; j++) { int sum = 0, dem = 1; int gau = precal[j][dem]; if(a[i] <= vt[j - 1] && vt[j] - 1 <= b[i]) { for(int t = i - 1; t >= 1; t--) { sum = (sum + gau * s[t][j - 1]) % somod; if(a[k] <= vt[j - 1] && vt[j] - 1 <= b[k]) gau = (gau + precal[j][++dem] - vt[j] + vt[j - 1] + somod) % somod; } sum = (sum + vt[j] - vt[j - 1]) % somod; } s[i][j] = (s[i][j - 1] + sum) % somod; } } int ans = 0; for(int i = 1; i <= n; i++) ans = (ans + s[i][k]) % somod; cout << ans; }

Compilation message (stderr)

boat.cpp: In function 'int32_t main()':
boat.cpp:50:13: warning: unused variable 'sum' [-Wunused-variable]
         int sum = 0;
             ^~~
boat.cpp:26:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:26:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...