Submission #1241648

#TimeUsernameProblemLanguageResultExecution timeMemory
1241648tminhTrains (BOI24_trains)C++20
100 / 100
194 ms6420 KiB
#include "bits/stdc++.h" using namespace std; #define task "" #define ll long long #define endl '\n' #define fi first #define se second #define vall(a) (a).begin(), (a).end() #define sze(a) (int)a.size() #define pii pair<int, int> #define pll pair<ll, ll> #define ep emplace_back #define pb push_back #define pf push_front const ll mod = 1e9 + 7; const int N = 1e5 + 5; const ll oo = 1e18; const int base = 300; bool START; int n, d[N], x[N]; ll dp[N], f[base + 5][base + 5]; vector<int> del[N]; ll Mod(ll x) { if (x >= mod) return x - mod; if (x < 0) return x + mod; return x; } inline void solve() { dp[0] = 1; ll ans = 0; for (int i = 0; i < n; ++i) { for (int j : del[i]) f[d[j]][j % d[j]] = Mod(f[d[j]][j % d[j]] - dp[j]); for (int j = 1; j <= base; ++j) dp[i] = Mod(dp[i] + f[j][i % j]); if (!d[i] || d[i] > n) { ans = Mod(ans + dp[i]); continue; } if (d[i] > base) { for (int j = 1; i + j * d[i] < n && j <= x[i]; ++j) dp[i + j * d[i]] = Mod(dp[i + j * d[i]] + dp[i]); } else { f[d[i]][i % d[i]] = Mod(f[d[i]][i % d[i]] + dp[i]); ll lim = i + 1ll * d[i] * (x[i] + 1); if (lim <= n) del[lim].pb(i); } ans = Mod(ans + dp[i]); } cout << ans; } inline void input() { cin >> n; for (int i = 0; i < n; ++i) cin >> d[i] >> x[i]; return solve(); } bool END; int main() { if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); input(); cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl; cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n"; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(task ".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...