Submission #1111515

#TimeUsernameProblemLanguageResultExecution timeMemory
1111515simuyuTrains (BOI24_trains)C++14
8 / 100
2116 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pl pair<long, long> #define pll pair<ll, ll> #define f first #define s second #define MOD 1000000007 ll ress[100005], ds[100005], xs[100005]; vector<vector<ull> > apsums; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll N; cin >> N; for (ll i=1; i<1+N; i++) { cin >> ds[i] >> xs[i]; apsums.push_back(vector<ull>()); apsums[apsums.size()-1].push_back(0); } ull xp, res; for (ll idx=N; idx>0; idx--) { //cout << "PROCESSING " << idx << endl; // if no trains if (ds[idx] == 0) { res = 1; ress[idx] = 1; } else { xp = min(xs[idx], (N-idx)/ds[idx]); if (xp == 0) { ress[idx] = 1; res = 1; } else { /* res = 1; // now loop for (ll p=1; p<=xp; p++) { res += ress[idx+ds[idx]*p]; res = res%MOD; } */ //cout << "CHECKED IFS" << endl; // apsums is from the back. if we need 2, length is 5, then we take apsums[idx][4] - apsums[idx][2] //cout << "XP: " << xp << ", SIZE: " << apsums[idx-1].size() << endl; //cout << apsums[idx-1][apsums[idx-1].size()-1] << ' ' << apsums[idx-1][apsums[idx-1].size()-1-xp] << endl; res = 1+(apsums[idx-1][apsums[idx-1].size()-1] + MOD - apsums[idx-1][apsums[idx-1].size()-1-xp])%MOD; // add to memo ress[idx] = res; } } //cout << "GOT RES: " << res << endl; /*cout << "APSUMS: " << endl; for (int i=0; i<apsums.size(); i++) { cout << ds[i+1] << ": "; for (int j=0; j<apsums[i].size(); j++) { cout << apsums[i][j] << ' '; } cout << endl; } cout << endl;*/ //cout << "LEN APSUMS: " << apsums.size() << endl; // add to apsums // index from back ig = N-idx, if it's % isajfe = 0 then add for (int i=0; i<N; i++) { if (ds[i+1] == 0) continue; //cout << "NEXT START" << endl; //cout << N-idx-i << ' ' << (N-idx)%ds[i+1] << endl; // it should be -( (N-idx)-(N-i) ) to get distance from idx to i --> basically idx-i if (((idx-i-1)%ds[i+1]) == 0) { //cout << apsums[i].size() << ", VAL: " << (apsums[i][apsums[i].size()-1]+res)%MOD << endl; // add to the apsums apsums[i].push_back((apsums[i][apsums[i].size()-1] + res)%MOD); //cout << "YES " << i << " WHEN MAX " << N << endl; } //cout << "OKAY END" << endl; } //cout << "ADDED TO APSUMS" << endl; } /*cout << "DEBUG: "; for (int i=1; i<=N; i++) { cout << ress[i] << ' '; } cout << endl << endl; cout << "APSUMS: " << endl; for (int i=0; i<apsums.size(); i++) { cout << ds[i+1] << ": "; for (int j=0; j<apsums[i].size(); j++) { cout << apsums[i][j] << ' '; } cout << endl; } cout << endl;*/ cout << ress[1] << '\n'; return 0; }
#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...