This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unistd.h>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, int> pil;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
const int SS = 1e5 + 8, MOD = 1e9 + 7;
class Solution{
public:
ll N, di, xi, DP[SS];
vector<pll> arr = {{-1, -1}};
ll helper(ll curr){
auto [diff, x] = arr[curr];
DP[curr] = 1;
if (diff == 0) return 1;
for (int child = diff + curr, t = 0; child <= N && t < x; child += diff, t++){
DP[curr] += helper(child);
}
return (DP[curr] %= MOD);
}
ll profitProfit(){
cin >> N;
fill(DP, DP + SS, -1);
for (int i = 0; i < N; i++){
cin >> di >> xi;
arr.push_back( make_pair(di, xi) );
}
return helper(1);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
Solution p;
cout << p.profitProfit();
}
Compilation message (stderr)
Main.cpp: In member function 'll Solution::helper(ll)':
Main.cpp:26:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | auto [diff, x] = arr[curr];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |