이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int MAX = 1e5 + 10;
int N;
int d[MAX], t[MAX];
void input(){
cin >> N;
for(int i=1; i<=N; i++){
cin >> d[i] >> t[i];
}
}
namespace subtask2{
int f[MAX];
void solve(){
f[1] = 1;
for(int i=1; i<=N; i++) if(f[i] && d[i]){
for(int j=1; j<=t[i]; j++){
if(i + 1LL * d[i] * j > N) break;
add(f[i + d[i] * j], f[i]);
}
}
int ans = 0;
for(int i=1; i<=N; i++){
add(ans, f[i]);
}
cout << ans << '\n';
}
}
namespace subtask3{
bool check(){
for(int i=1; i<=N; i++){
if(d[i] != 1) return false;
}
return true;
}
int f[MAX];
void solve(){
f[1] = 1;
for(int i=1; i<=N; i++){
add(f[i], f[i - 1]);
int p = min(1LL * N, i + 1LL * d[i] * t[i]);
add(f[i + 1], 1);
sub(f[p + 1], 1);
}
int ans = 0;
for(int i=1; i<=N; i++){
add(ans, f[i]);
}
cout << ans << '\n';
}
}
namespace subtask5{
const int S = sqrt(MAX + 10);
int f[MAX], g[MAX][S];
void solve(){
for(int i=N; i>=1; i--){
if(d[i] < S){
if(d[i] && t[i]){
ll st = i + d[i];
ll en = i + d[i] * (t[i] + 1);
if(st <= N){
if(en <= N)
add(f[i], (g[st][d[i]] - g[en][d[i]] + MOD) % MOD);
else
add(f[i], g[st][d[i]]);
}
}
}
else{
for(int j=1; j<=t[i] && i + 1LL * j * d[i] <= N; j++){
add(f[i], f[i + 1LL * j * d[i]]);
}
}
f[i]++;
for(int j=1; j<S; j++) if(i + j <= N){
g[i][j] = f[i];
add(g[i][j], g[i + j][j]);
}
}
cout << f[1];
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("netw.inp", "r", stdin);
// freopen("netw.out", "w", stdout);
input();
return subtask5::solve(), 0;
return 0;
}
# | 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... |