Submission #967952

#TimeUsernameProblemLanguageResultExecution timeMemory
967952duckindogBoat (APIO16_boat)C++17
31 / 100
1525 ms524288 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> using namespace std; const int N = 500 + 10, M = 1'000'000'007; int n; int a[N], b[N]; int f[2][1'000'010]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i]; vector<int> rrh; for (int i = 1; i <= n; ++i) { for (int j = a[i]; j <= b[i]; ++j) rrh.push_back(j); } sort(rrh.begin(), rrh.end()); rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin()); f[0][0] = 1; for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1; for (int i = 1; i <= n; ++i) { bool id = i & 1, p = id ^ 1; int it = lower_bound(rrh.begin(), rrh.end(), a[i]) - rrh.begin() + 1; auto add = [&](auto& value, const auto& delta) { value += delta; if (value >= M) value -= M; }; f[id][0] = f[p][0]; for (int j = 1; j <= rrh.size(); ++j) { f[id][j] = f[id][j - 1]; if (j < it || j > b[i] - a[i] + it) { add(f[id][j], f[p][j]); add(f[id][j], M - f[p][j - 1]); } else { add(f[id][j], f[p][j]); } } } cout << f[n & 1][rrh.size()] - 1 << "\n"; cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n"; }

Compilation message (stderr)

boat.cpp: In function 'int32_t main()':
boat.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for (int j = 1; j <= rrh.size(); ++j) f[0][j] = 1;
      |                   ~~^~~~~~~~~~~~~
boat.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int j = 1; j <= rrh.size(); ++j) {
      |                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...