Submission #1273839

#TimeUsernameProblemLanguageResultExecution timeMemory
1273839icebearTrains (BOI24_trains)C++20
100 / 100
240 ms120956 KiB
// ~~ icebear ~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; template<class T> bool minimize(T &a, const T &b) { if (a > b) return a = b, true; return false; } template<class T> bool maximize(T &a, const T &b) { if (a < b) return a = b, true; return false; } #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define FORR(i,a,b) for(int i=(a); i>=(b); --i) #define REP(i, n) for(int i=0; i<(n); ++i) #define RED(i, n) for(int i=(n)-1; i>=0; --i) #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() #define task "cuuho" const int MOD = 1e9 + 7; const int inf = 1e9 + 27092008; const ll INF = 1e18 + 27092008; const int N = 1e5 + 5; const int S = 300; int n, d[N], x[N], dp[N], pref[N][S + 5]; void init(void) { cin >> n; FOR(i, 1, n) cin >> d[i] >> x[i]; } void process(void) { dp[1] = 1; FOR(i, 1, n) { FOR(j, 1, S) if (i >= j) { (pref[i][j] += pref[i - j][j]) %= MOD; (dp[i] += pref[i][j]) %= MOD; } if (d[i] <= S && i + d[i] <= n) { (pref[i][d[i]] += dp[i]) %= MOD; ll e = i + 1LL * d[i] * (x[i] + 1); if (e <= n) pref[e][d[i]] = (pref[e][d[i]] - dp[i] + MOD) % MOD; } else { FOR(j, 1, x[i]) { if (i + j * d[i] > n) break; (dp[i + j * d[i]] += dp[i]) %= MOD; } } } int ans = 0; FOR(i, 1, n) (ans += dp[i]) %= MOD; cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int tc = 1; // cin >> tc; while(tc--) { init(); process(); } return 0; }

Compilation message (stderr)

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