Submission #1278330

#TimeUsernameProblemLanguageResultExecution timeMemory
1278330phuocrucppTrains (BOI24_trains)C++20
100 / 100
152 ms125308 KiB
/*ㅤ∧_∧
 ( ・∀・)
 ( つ┳⊃
ε (_)へ⌒ヽフ
 (  ( ・ω・)
 ◎―◎   ⊃  ⊃
BePhuongSuperSuwi
From TK4 - CHT
ㅤㅤ/ ⌒\____
  /・   )  \
 /ノへ ノ    /|
ノ    \\ |/_/_/*/


#include<bits/stdc++.h>
#define task "main"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
//#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii, ii>
#define base 341
#define MASK(i) (1ll << i)
#define oo 1e18
#define isOn(x,i) ((x) & MASK(i))
#define bitOn(x,i) ((x) | MASK(i))
#define bitOff(x,i) ((x) & ~MASK(i))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
using namespace std;
//using namespace __gnu_pbds;
const int maxn = 1e5 + 5;
int n, d[maxn], x[maxn], dp[maxn], mod = 1e9 + 7, p[325][maxn];

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);
    }
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> d[i] >> x[i];
       // d[i] = x[i] = 1e9;
    }

    int S = sqrt(n);

    for (int i = n; i >= 1; i--) {
        if (d[i] == 0)
            dp[i] = 1;
        else {
            int lim = min(x[i], (n - i) / d[i]), sum = 0;

            if (d[i] > S) {
                for (int k = 1; k <= lim; k++) {
                    int x = i + k * d[i];
                    sum = (sum + dp[x]) % mod;
                }
            }
            else {
                int pos1 = i + d[i];
                int pos2 = i + d[i] * (lim + 1);

                int s1 = (pos1 <= n ? p[d[i]][pos1] : 0);
                int s2 = (pos2 <= n ? p[d[i]][pos2] : 0);
                sum = ((s1 - s2) % mod + mod) % mod;
            }
            dp[i] = (1 + sum) % mod;
        }
        for(int j=1;j<=S;j++){
            int idx = i + j;
            int val = dp[i];
            if(idx <= n) {
                val = (val + p[j][idx]) % mod;
            }
            p[j][i] = val;
        }
    }

    cout << dp[1] % mod;
}


 

Compilation message (stderr)

Main.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main() {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         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...