Submission #1065200

#TimeUsernameProblemLanguageResultExecution timeMemory
1065200ttttttttttttthTrains (BOI24_trains)C++17
0 / 100
3 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const long long N = 1e5 + 5; const long long inf = 1e9; const long long mod = 1e9 + 7; const int Block = 300; int n, d[N], x[N]; int dp[N], f[N][Block + 5]; signed main() { ios_base :: sync_with_stdio (0); cin.tie (0); freopen ("BUS.inp", "r", stdin); freopen ("BUS.out", "w", stdout); cin >> n; for (int i = 1; i <= n; i++) { cin >> d[i] >> x[i]; } for (int i = n; i >= 1; i--) { dp[i] = 0; if (d[i] == 0) { dp[i] = 1; } else if (d[i] > Block) { for (int j = i + d[i]; j <= min(n, i + d[i] * x[i]); j += d[i]) { dp[i] = (dp[i] + dp[j]) % mod; } dp[i] = (dp[i] + 1) % mod; } else { dp[i] = 1; dp[i] = (dp[i] + ((i + d[i] <= n) ? (f[i + d[i]][d[i]]) : 0)) % mod; dp[i] = (dp[i] - ((i + d[i] * (x[i] + 1) <= n) ? (f[(i + d[i] * (x[i] + 1))][d[i]]) : 0) + mod * mod) % mod; } for (int j = 0; j <= Block; j++) { f[i][j] = ((i + j <= n ? f[i + j][j] : 0) + dp[i]) % mod; } } cout << dp[1]; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:18:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen ("BUS.inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen ("BUS.out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...