Submission #1066453

#TimeUsernameProblemLanguageResultExecution timeMemory
1066453Essa2006Trains (BOI24_trains)C++14
100 / 100
108 ms7096 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define FF first #define SS second #define all(a) a.begin(), a.end() #define mod (ll)(1000000007) int main() { ios_base::sync_with_stdio(0);cin.tie(0); int n; cin >> n; vector<int> D(n), X(n); vector<ll> dp(n, 1); vector<vector<int>> Sub(n); int sq = sqrt(1e5); for (int i = 0; i < n; i++) { cin >> D[i] >> X[i]; if (D[i] < sq && i + (ll)D[i] * (X[i] + 1) < n && D[i]) { Sub[i + D[i] * (X[i] + 1)].push_back(i); } } vector<vector<int>> Ways(sq + 1); for (int i = 1; i <= sq; i++) { Ways[i].resize(i); } for (int i = n - 1; i >= 0; i--) { if (D[i] >= sq) { for (int j = 1; j <= X[i] && i + (ll) j * D[i] < n;j++) { dp[i] += dp[i + j * D[i]]; dp[i] %= mod; } } else if (D[i]){ dp[i] += Ways[D[i]][i % D[i]]; dp[i] %= mod; } for (int j = 1; j <= sq; j++) { Ways[j][i % j] += dp[i]; Ways[j][i % j] %= mod; } for (int j = 0; j < Sub[i].size(); j++) { dp[Sub[i][j]] -= Ways[D[Sub[i][j]]][i % D[Sub[i][j]]]; dp[Sub[i][j]] += mod, dp[Sub[i][j]] %= mod; } } cout << dp[0]; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int j = 0; j < Sub[i].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...
#Verdict Execution timeMemoryGrader output
Fetching results...