Submission #523781

#TimeUsernameProblemLanguageResultExecution timeMemory
523781vonatlusBoat (APIO16_boat)C++17
31 / 100
1625 ms524292 KiB
/// adil sultanov | vonat1us #pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:36777216") #include<bits/stdc++.h> #define x first #define y second #define pb push_back #define sz(x) (int) x.size() #define all(z) (z).begin(), (z).end() using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = 1e9 + 7; const int INF = 1e9 + 1e2; void fin() { #ifdef AM freopen(".in", "r", stdin); #endif } const bool flag = 0; const int N = 510; int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int a[N], b[N], len[N]; vector<int> dp[N]; void ma1n() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; len[i] = b[i]-a[i]+1; } if (n == 1) { cout << b[1]-a[1]+1, exit(0); } dp[0].resize(1); for (int i = 1; i <= n; ++i) { dp[i].resize(len[i]+1); dp[i][0] = add(dp[i-1][0], dp[i-1][len[i-1]]); for (int x = a[i]; x <= b[i]; ++x) { for (int j = 1; j < i; ++j) { int r = min(b[j], x-1); if (a[j] <= r) { dp[i][x-a[i]+1] = add(dp[i][x-a[i]+1], dp[j][r-a[j]+1]); } } } for (int x = 1; x <= len[i]; ++x) { if (x+1 <= len[i]) dp[i][x+1] = add(dp[i][x+1], dp[i][x]); dp[i][x] = add(dp[i][x], x); } } cout << add(dp[n][0], dp[n][len[n]]); } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr), fin(); int ts = 1; if (flag) { cin >> ts; } while (ts--) { ma1n(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...