Submission #1320900

#TimeUsernameProblemLanguageResultExecution timeMemory
1320900aaaaaaaaTrains (BOI24_trains)C++20
0 / 100
10 ms13116 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int mxN = 1e5 + 10;
const int mxS = 346;
int dp[mxN], dp2[mxN][mxS + 5];
int add(int x, int y){
    return ((x % mod) + (y % mod)) % mod;
}
void testCase() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n + 1);
    for(int i = 1; i <= n; ++i){
        cin >> v[i].first >> v[i].second;
    }
    for(int i = 1; i <= n; ++i) dp[i] = 1;
    for(int i = n; i >= 1; --i){
        if(v[i].first == 0) {
            for(int j = 1; j <= mxS; ++j){
                if((i + j) <= n) dp2[i][j] = add(dp2[i + j][j], dp[i]);
                else dp2[i][j] = dp[i];
            }
        }
        else{
            if(v[i].first >= mxS){
            for(int j = i + v[i].first; j <= n; j += v[i].first){
                dp[i] = add(dp[i], dp[j]);
            }
            }else{
                if((i + v[i].first) <= n) dp[i] = add(dp2[i + v[i].first][v[i].first], 1);
            }
            for(int j = 1; j <= mxS; ++j){
                if((i + j) <= n) dp2[i][j] = add(dp2[i + j][j], dp[i]);
                else dp2[i][j] = dp[i];
            }
        }
    }
    cout << add(dp[1], mod) << "\n";
}
signed main(){
    freopen("input.txt", "r", stdin);
    freopen("algo.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    testCase();
    return 0;
}

Compilation message (stderr)

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