Submission #995352

#TimeUsernameProblemLanguageResultExecution timeMemory
995352LoboTrains (BOI24_trains)C++17
21 / 100
779 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = 1e18 + 10; const int inf1 = 1e9 + 10; #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const int maxn = 1e5+10; const int B = 0; const int mod = 1e9+7; int n, d[maxn], x[maxn], dp[maxn], tran1[maxn][B+1]; vector<int> tran2[maxn]; void solve() { cin >> n; for(int i = 1; i <= n; i++) { cin >> d[i] >> x[i]; if(d[i] == 0 or x[i] == 0) continue; if(d[i] > B) { for(int j = 1; j <= x[i] && i+j*d[i] <= n; j++) { tran2[i].pb(i+j*d[i]); } } else if(i+d[i] <= n) { tran1[i][d[i]] = max(tran1[i][d[i]],x[i]); } } dp[1] = 1; vector<int> fq(n+1,0); int ans = 0; for(int i = 1; i <= n; i++) { for(auto j : tran2[i]) { if(fq[j]) continue; fq[j] = 1; dp[j] = (dp[j]+dp[i])%mod; } for(auto j : tran2[i]) { fq[j] = 0; } for(int dif = 1; dif <= B; dif++) { if(tran1[i][dif] != 0) { dp[i+dif] = (dp[i+dif]+dp[i])%mod; tran1[i+dif][dif] = max(tran1[i+dif][dif],tran1[i][dif]-1); } } ans = (ans+dp[i])%mod; } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE //freopen("in.in", "r", stdin); //freopen("out.out", "w", stdout); #endif int tt = 1; // cin >> tt; while(tt--) { solve(); } }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:33:41: warning: array subscript -1 is below array bounds of 'long long int [1]' [-Warray-bounds]
   33 |       tran1[i][d[i]] = max(tran1[i][d[i]],x[i]);
      |                            ~~~~~~~~~~~~~^
Main.cpp:33:41: warning: array subscript -1 is below array bounds of 'long long int [1]' [-Warray-bounds]
Main.cpp:33:20: warning: array subscript -1 is below array bounds of 'long long int [1]' [-Warray-bounds]
   33 |       tran1[i][d[i]] = max(tran1[i][d[i]],x[i]);
      |       ~~~~~~~~~~~~~^
#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...