이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;
int n;
vector<ll> dp;
vi d,x;
int m;
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
cin>>n;
if(n<=10000){
pii a(n);
REP(i,0,n)cin>>a[i].F>>a[i].S;
vector<ll> ans(n,0);
ans[0]=1;
REP(i,0,n){
int k=a[i].F;
if(k==0)continue;
REP(j,1,a[i].S+1){
if(i+j*k>=n)break;
ans[i+j*k]+=ans[i];
ans[i+j*k]%=M;
}
}
ll val=0;
REP(i,0,n){
val+=ans[i];
val%=M;
}
cout<<val;
return 0;
}
d.resize(n);x.resize(n);
REP(i,0,n)cin>>d[i]>>x[i];
m=sqrt(n)+1;
ll ans=0;
vector<ll> val(n,0);
val[0]=1;
vector<vector<ll>> arr(n,vector<ll>(m,0));
REP(i,0,n){
REP(j,1,m){
if(arr[i][j]==0)continue;
val[i]+=arr[i][j];
val[i]%=M;
if(i+j<n){
arr[i+j][j]+=arr[i][j];
arr[i+j][j]%=M;
}
}
if(d[i]==0)continue;
if(d[i]<m){
if(i+d[i]<n){
arr[i+d[i]][d[i]]+=val[i];
arr[i+d[i]][d[i]]%=M;
}
}
else{
REP(j,1,x[i]+1){
if(i+d[i]*j>=n)break;
val[i+d[i]*j]+=val[i];
val[i+d[i]*j]%=M;
}
}
}
REP(i,0,n){
ans+=val[i];
ans%=M;
}
cout<<ans;
}
# | 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... |