Submission #1066452

# Submission time Handle Problem Language Result Execution time Memory
1066452 2024-08-19T22:00:26 Z Essa2006 Trains (BOI24_trains) C++14
34 / 100
85 ms 5724 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<int> D(n), X(n);
    vector<ll> dp(n, 1);
    
    vector<vector<int>> Sub(n);
    int sq = sqrt(1e5);
    
    for (int i = 0; i < n; i++) {
        cin >> D[i] >> X[i];
        
        if (D[i] < sq && i + (ll)D[i] * (X[i] + 1) < n && D[i]) {
            Sub[i + D[i] * (X[i] + 1)].push_back(i);
        }
    }
    

    vector<vector<int>> Ways(sq + 1);
    for (int i = 1; i <= sq; i++) {
        Ways[i].resize(i);
    }
    
    for (int i = n - 1; i >= 0; i--) {
        if (D[i] >= sq) {
            for (int j = 1; j <= X[i] && i + (ll) j * D[i] < n;j++) {
                dp[i] += dp[i + j * D[i]];
                dp[i] %= mod;
            }
            
            
        }   
        else if (D[i]){
            dp[i] += Ways[D[i]][i % D[i]];
            dp[i] %= mod;
        }
        
        for (int j = 1; j <= sq; j++) {
            Ways[j][i % j] += dp[i];
            Ways[j][i % j] %= mod;
        }
        
        for (int j = 0; j < Sub[i].size(); j++) {
            dp[Sub[i][j]] -= Ways[i][i % D[Sub[i][j]]];
            dp[Sub[i][j]] += mod, dp[Sub[i][j]] %= mod;
        }
        
       
    }
    cout << dp[0];
}   

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int j = 0; j < Sub[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3164 KB Output is correct
2 Correct 32 ms 2648 KB Output is correct
3 Correct 79 ms 5724 KB Output is correct
4 Correct 56 ms 4280 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 8 ms 1116 KB Output is correct
8 Correct 85 ms 5648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Incorrect 0 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -